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} ^hemant-patel\.com$ [NC] RewriteRule ^(.*)$ https://www.hemant-patel.site/$1 [R=301,L]

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

Written by Hemant Patel

Hemant, hailing from Bhopal, Madhya Pradesh, India, is a web developer and occasional blogger passionate about exchanging ideas and addressing problems in his coding journey.