Simple .htaccess redirection and rewriting

Here is quick code for creating redirection for your web site:

Redirecting to www:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

This will redirect all request from to

Redirecting to www with https:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$$1 [R,L]

This will redirect all request to

Access page with multiple names/urls (SEO trick):

# The page login.php will be accessible by and
RewriteEngine On
RewriteRule ^login login.php [L]

Pass querystring (GET) values to PHP page:

# This will send id (GET) value as 1 to page checkout.php where you can get it into script via $_REQUEST[‘id’]

RewriteEngine On
RewriteRule ^checkout/id checkout.php?id=1 [L]

Above codes can be used for basic SEO and URL rewriting/redirection.

How to deal with hackers for web server? Sym links solution

Nowadays hacking becomes more ordinary, and most web hosting companies are being targeted and there is no proper solution to prevent or to make your server 100% secure.

As a web hosting provider, we do always try to secure our servers from the hackers sometime it works but sometimes we failed.

Today i want to describe some commands for Linux WHM/cPanel based servers commands to make your server secure not 100% but it works out of the box. As i am using these commands to not prevent server from hacking but these commands are very useful and does not allow hackers to do anything on the server with other accounts.

I assume, you already familiar with the sym links those are auto-created on the linux based servers, they allow hackers to create link directory/files with the other accounts, so they can access other accounts those are related to other cPanel accounts on the server.

If you disable sym links on the server, hackers cannot hack into your server or if they are able to hack one account, other accounts will remain safe and will not get affected.

Well, disabling sym links is not the proper solution and also disturbs functionality of some scripts on the server like joomla and wordpress.

Here i would like to describe some linux commands those are used to prevent creation of new symlinks in the root directory of an account, on cPanel it is public_html.

Follow the following steps to:

  • Login to your server via ssh with root access.
  • Now make a check if there are sym links  already created on the server.
  • Execute following command for cPanel:
  •  # find /home*/*/public_html -type l
  • Above command will display all the sym links for all cPanel accounts created in public_html and sub directories if any.
  • Now, add a cron job to check for sym links  and remove them if found, you can set any interval, in the below command i set it to every minutes.
  • So the command checks and removes all sym links inside the public_html directory and their sub directories.
  • Execute the following commands to add cron job:
  • # crontab -e
  • A crontab file will be opened in default text-editor.
  • Go to last line and add below command:
  • */5 * * * * find /home*/*/public_html -type l -exec rm -rfv {} \;
  • Now, save your crontab file to make it functional.
  • And you’re done, this will check for sym links inside public_html directory and will remove them if found.
  • TIP: you can also change the location of your directory for other control panels, by replacing /home*/*/public_html
  • Note: Do not execute command on system directories, your server will be destroyed and will become unstable.

That is all, comments are welcome : ) if it works for you.

Change timezone with .htaccess

Here is short code that changes the timezone for the linux server, you can add this single line of code into your .htaccess file to change the timezone/locale for your PHP files.

Follow the below steps:

Add the following code into .htaccess file and upload it to the server:

php_value date.timezone “America/New_York”

Now check the changes by adding following code into your PHP file:

echo date(‘h:s d-m-y’);

It will display your current time according to the timezone you have mentioned in the .htaccess file.

Here is the list of all supported locales/timezones for PHP:


Thats all.