(Page 2 of 6)
Avoiding duplicate content problems by canonicalize the domain names and index pages with the help of mod rewrite.
Canonicalization is the process of picking the best url when there are several choices, and it usually refers to home pages. For example, most people would consider these the same urls:
- http://www.example.com/
- http://example.com/
- http://www.example.com/index.html
However technically all of these urls are different and a web server could return completely different content for all the urls above.
But in most cases the web server return for all the urls above the same content, what can causes duplicate content problems.
You can avoid that by redirecting non-www and IP address to www hostnames
and /index.html pages to / pages.
RewriteEngine On
# Redirect non-www and IP addresses to www.
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
EXPLAIN: In this case the requested url http://example.com/foo.html would redirected to the url http://www.example.com/foo.html.
# Redirect direct client requests for "<anything>/index.html" to "<anything>/"
RewriteRule ^(([^/]+/)*)index\.html http://www.example.com/$1 [R=301,L]
EXPLAIN: In this case the requested url http://www.example.com/index.html would redirected to the url http://www.example.com/.
NEXT » Redirect relocated urls with mod rewrite
|