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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>