HTTP Error 301: Permanent Redirect
After reading many discussion about "www." is deprected, I visit many sites and the most of them use the "www." in the domain name. At this point I decide that the request to http://aadmm.de should permanetly redirect to http://www.aadmm.de, but how do I implement this?
Changes in the .htaccess file
On my web server I must do following, that the request to http://aadmm.de is permanently redirect to http://www.aadmm.de.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.aadmm\.de$ [NC]
RewriteRule ^(.*)$ http://www.aadmm.de/$1 [R=301,L]
The [R=301,L] means redirect the client and send a 301 status code (R=301) and make this the last rule (L).
And the other way?
Change the .htaccess file to following, if you will have that all requests from http://www.aadmm.de will go to http://aadmm.de.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.aadmm\.de$ [NC]
RewriteRule ^(.*)$ http://aadmm.de/$1 [R=301,L]
More complex sample with 301 redirect
A few weeks ago, I moved some contents to a new location on an other domain. Here is a sample with was working for me.
# permanent redirect - moving files from domain.old to domain.new
RewriteEngine On
Redirect permanent /w3c_qa_check.html http://www.aadmm.de/en/notes/w3c_qa_check.htm
Redirect permanent /wai_check.html http://www.aadmm.de/en/notes/wai_check.htm
Please note, that the old location doesn't have the full URLs, only the file names are needed. After two weeks the search engines had changed the old URLs for this files to the new URLs.