Redirect old domain to new domain with 301

Here are the few lines of code you can add into your .htaccess to redirect your old domain to new domain with 301 (permanent redirect) code.

Open .htaccess file in any editor and add following below lines, please replace websterz.info with your own domain.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^websterz.info [NC,OR]
RewriteCond %{HTTP_HOST} ^www.websterz.info [NC]
RewriteRule ^(.*)$ http://websterz.info/$1 [L,R=301,NC]

 

That’s all 🙂

Simple .htaccess redirection and rewriting

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

Redirecting to www:

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

This will redirect all request from http://example.com to http://www.example.com

Redirecting to www with https:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

This will redirect all request to https://www.example.com

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

# The page login.php will be accessible by http://example.com/login and http://example.com/login.php
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.