Domain migration in Apache using .htaccess
The Apache method
I used to have my old web site at erlend.gausen.net where my relative Monica had some space to spare, but when I decided to remake the site dynamically I had to move it to my own hosting here at erlendgausen.net.
To let visitors still reach me and to avoid confusion, the following lines added to the .htaccess file at the old site instructs Apache to redirect the visitor to my new domain:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !erlendgausen.net$ [NC]
RewriteRule ^(.*)$ http://erlendgausen.net/$1 [L,R=301]
Any files, folders and arguments behind the domain name will be kept the same. Only the domain name is rewritten.
The ‘R=301′ is an instruction to the HTTP client (browser/search engine) that the move is permanent. Some search engines might take notice of it. Otherwise, the switch should be quite transparent to readers.
To check out the result, you can test these two similar links that just have a subtle difference between them:
- http://erlendgausen.net/technical/domain-migration
- http://erlend.gausen.net/technical/domain-migration
A client-side alternative without javascript
An alternative to redirecting directly and transparently is using HTML meta data to perform client-side browser redirection. This is most usually done using javascript, but I prefer using this method for it’s better compatibility, reliability and efficiency.
meta content=”5;url=http://erlendgausen.net” http-equiv=”Refresh” /
The code is a tag, so enclose it in < and > brackets.
The digit, in this case 5, determines the delay in seconds to the redirection should take place. Also, this function can be used to set up a simple slide show where new pages are automatically displayed at given time intervals.