Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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


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.