Monday, December 7, 2009

Redirect Webpages to Another Domain

SkyHi @ Monday, December 07, 2009
Redirect Webpages to Another Domain
Filed in: Web Development — September 22nd, 2004

advertisement

In case you need to change an existing website to another domain name. You don’t wish to lost your visitors. You want to auto redirect visitors to new location. You want address like “http://www.OldDomain.com/foldername/filename.htm” will lead visitor to “http://www.NewDomain.com/foldername/filename.htm”, as well as ALL other URL.

If your web server is using Apache HTTP Server then you can use the powerful mod_rewrite module to do the task. It required only few lines of code.

Create a “.htaccess” file in your OldDomain’s web root folder(example: /public_html/) then enter the following codes in the file.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^OldDomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.OldDomain.com$
RewriteRule ^(.*)$ http://www.NewDomain.com/$1 [R=301,L]

Done! Now all visitors to OldDomain.com(regardless the path) will auto redirected to NewDomain.com(with appending path).

Reference: http://www.liewcf.com/archives/2004/09/redirect-webpages-to-another-domain/