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

I'm sure I'm missing a trick here but I can't work out how to remove the trailing slash from a file name in a URL using an Apache RewriteRule.

My URL would be something like this:

I need the URL to become

Any help would be appreciated.


share|improve this question
edited your question for clarity. – Massimo Jun 17 '10 at 13:37

1 Answer 1

up vote 3 down vote accepted

Where do you want to do this?

In an Apache rewrite rule?
In a PHP page?
In a bash script?

Plase specify...


RewriteRule. Ok. This should do what you need:

RewriteRule ^(.+)/$  /$1 [R=301,L]
share|improve this answer
Sorry, as an apache rewrite rule, so a .htaccess file – eek Jun 17 '10 at 13:25
...why the downvote?!? – Massimo Jun 17 '10 at 13:28
hmm wasn't me :/ – eek Jun 17 '10 at 13:29
One more example of why people should have to leave a comment when down-voting (even if that comment is anonymous). – Chris S Jun 17 '10 at 14:15
@Massimo the RewriteRule only says to remove the slash, but if the DirectorySlash directive is set to "ON", which is the default, it would cause them to each override the other (ie. a loop). See – matthew Jun 17 '10 at 18:07

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.