301 redirect

Redirecting users to same pages while migrating to new domain

301 redirect

While migrating my previous domain name to current one i had to gather some domain redirection tools in order to help myself to redirect my old domain pages and posts to current one. Fortunately i did not change the site page hence i could do it with less effort. Listing a few useful redirection rules here.

# if someone requests my about-us page of old domain, redirect it to about-us on new domain

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.myolddomain\.com$
RewriteRule ^about-us$ http://www.mynewdomain.com/about-us [L,R=301]

I had a few .php pages in old website and want each .php page to be redirected to a sub-directory of new domain as i decided to place all .php pages in a php-pages sub-directory of new domain.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.myolddomain\.com$
RewriteRule ^(.+).php$ http://www.mynewdomain.com/php-pages/$1.php [L,R=301]

In case i just wanted to redirect any request from old server to the corresponding area or page in new server the following code would be more than useful. Each request would be redirected to corresponding page.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.myolddomain\.com$
RewriteRule (.*) http://www.mynewdomain.com/$1 [L,R=301]

In case i just wanted to just redirect any request on old domain to home page of new domain

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.myolddomain\.com$
RewriteRule ^$ http://www.mynewdomain.com/ [L,R=301]

Leave a Reply

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