Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I want to make rewrite to rewrite to

I can do that with this rewrite configuration:

RewriteCond %{HTTP_HOST} ^(www\.)?$  
RewriteCond %{REQUEST_URI} !^/*)  
RewriteCond %{REQUEST_URI} ^(.*)/$  
RewriteRule ^(.*) /$1  [L]

But I also want to redirect the same without trailing slash: redirect to redirect to

I have tried with this:

RewriteCond %{HTTP_HOST} ^(www\.)?$
RewriteCond %{REQUEST_URI} !^/*)
RewriteCond %{REQUEST_URI} !^(.*)/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])$ $1/ [R=301,L]

but does not work, it redirects to:


do you know a solution to this (without touching mod-dir conf)?

share|improve this question

4 Answers 4

up vote 1 down vote accepted

I've found the solution:

Options +FollowSymLinks
RewriteEngine On

# Fix missing trailing slashes.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/_l_/example\.com%{REQUEST_URI}/ -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# Rewrite sub domains.
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ /_l_/example\.com/$1 [QSA,L]

Thanks for your answers.

share|improve this answer


RewriteCond C:/wamp/www%{REQUEST_FILENAME} !-f



See also "What's up with REQUEST_FILENAME in mod_rewrite?"

share|improve this answer

I don't know where the "C:" is coming from in your browsers -- a more useful diagnostic would be to find the "Location" header from the HTTP response -- use something like Firebug, LiveHTTPHeaders, or telnet to get that.

Also, given that your second RewriteRule doesn't mention '' at all, I guess that you have both RewriteRules in your httpd.conf.

If that is the case, then the [L] modifier at the end of your first rule is stopping the second one from executing at all.

share|improve this answer

Why not just use this?

RewriteCond %{HTTP_HOST} ^(www\.)?$  
RewriteCond %{REQUEST_URI} !^/*)  
RewriteRule ^(.*) /$1  [L]
share|improve this answer
Not working, when I try it give me this – Paul Sep 4 '09 at 2:45

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.