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

| Views: 4462
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

Have comments or feedback on what I wrote? Please share them below! Found this useful? Consider sending me a small tip.
comments powered by Disqus
Other posts you may like...