Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I just took over development of a site and am having trouble figuring out the canonicalization rewrite rules (not my forte). I've pasted the code below.

The first bit seems straight-forward enough, stripping out index.html. The second part redirects non-www TO www and also appears to be redirecting to NO trailing slash: www.example.com (no "/"). I actually can't confirm the trailing slash part though (header sniffers don't show the / redirect).

Is there a trailing slash redirect in place? (btw, this code is years old, so am open to better, more efficient options).


RewriteEngine on 
RewriteBase / 

# Redirect INDEX.HTML 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.html\ HTTP/ 
RewriteRule index\.html$ http://www.example.com/%1 [R=301,L] 

# Redirect TO WWW with no trailing slash? 
RewriteCond %{HTTP_HOST} !^www\.example\.com 
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 
share|improve this question

1 Answer 1

up vote 0 down vote accepted

For a domain name, there is no way on the server side to control the trailing slash. (This is opposed to directories, where it is up to the server to manage the trailing slash.) This is because of the way that the HTTP protocol works. Every request must start with a slash. So the request for the home page of a site always looks like this, regardless of whether link is http://example.com or http://example.com/

GET / HTTP/1.1
Host: example.com

As a result, it is the browser that manages the trailing slash on the domain name. Nowadays, most browsers automatically put it in. There is nothing you can do server side to control whether a trailing slash appears at the end of your domain name.

share|improve this answer
    
Excellent summary, thanks! –  Carlos Parodi Feb 26 '13 at 19:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.