Igor Kromin |   Consultant. Coder. Blogger. Tinkerer. Gamer.

NOTE: This article is 3 years or older so its information may no longer be relevant. Read on at your own discretion! Comments for this article have automatically been locked, refer to the FAQ for more details.
I've moved my blog over to the new domain now and used the .htaccess file to redirect all requests from the old domain to this one.

Here's what I've used:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]


What this does is:
1. Turns on the URL rewriting engine in Apache
2. Sets the base URL to the root of the domain
3. Checks if the requested URL is not the new domain using case insensitive matching via the [NC] flag
4. Specifies the new URL to be the same as the requested URL, with the domain name changed to the new domain.

The L flag specifies this is the last rule to evaluate if a match is found and R=301 specifies that a HTTP 301 redirect is sent, which flags that the requested page has permanently moved to the new domain location.



-i

Hope you found this post useful...

...so please read on! I love writing articles that provide beneficial information, tips and examples to my readers. All information on my blog is provided free of charge and I encourage you to share it as you wish. There is a small favour I ask in return however - engage in comments below, provide feedback, and if you see mistakes let me know.

If you want to show additional support and help me pay for web hosting and domain name registration, donations, no matter how small, are always welcome!

Use of any information contained in this blog post/article is subject to this disclaimer.
comments powered by Disqus
Other posts you may like...