seo: domain redirecting with htaccess and apache mod_rewrite (domain with or without www)

Because of SEO regarding the duplicate content problem one of the basic rules is „don’t offer your same content on different urls“. Because of that reason it’s generally recommendable to use permantent redirects from http://example.com(/xyz…) to http://www.example.com(/xyz…)
This task is easy to implement, for example you could use a rewrite rule in your htaccess-file. Here’s an example:

[sourcecode language=“bash“]
RewriteEngine on
#Rewrite Rule something -> www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
[/sourcecode]

Using this rule every single url from your domain requested without www. will be redirected to the same url with www.

Schreibe einen Kommentar