Redirecting old domain name to new domain name with the old page to new page.

? Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Hiding .php extension by this rule. Entire .html page on your domain will be translate as .php page.

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*).html$ $1.php

Resolving canonical issue, Redirecting non-www domain to www domain vice versa.

// Non-www to www domain
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^bala-krishna\.com$ [NC] RewriteRule ^(.*)$ https://www.bala-krishna.com/$1 [R=301,L]

// Www to non-www domain
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.bala-krishna\.com$ [NC] RewriteRule ^(.*)$ http://bala-krishna.com/$1 [R=301,L]

Written by Bala Krishna

Bala Krishna is web developer and occasional blogger from Bhopal, MP, India. He like to share idea, issue he face while working with the code.