Redirect Webpages to Another Domain
Filed in: Web Development — September 22nd, 2004In 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:
Thought:
This code is better than my previous method, that not only redirect visitors to new domain but also follow the link path. Useful if the visitor follow a old domain link to your website.
Like this post? Please share:
Follow @liewcf on Twitter; Join Facebook page; Subscribe to free newsletter for updates like this article..




