Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to remove the last trailing slash of a URL. For example: I want to http://localhost/mysite/page/ rewrite to http://localhost/mysite/page.

I'm using this code on my localhost .htaccess.

Options +FollowSymLinks
RewriteEngine   on
RewriteRule ^([a-zA-Z0-9_-]+)/$ $1 [R=301,L]
RewriteRule ^([a-zA-Z0-9_-]+)$ web.php?page=$1

If I write on my browser http://localhost/mysite/index, it shows what I want. But if I write http://localhost/mysite/index/ it tells me "not found" and "the requested URL was not found on this server". I'm using UniServer on Windows 8.

share|improve this question

marked as duplicate by mdpc, Chris S Mar 10 '13 at 23:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

Try this instead:

# Remove trailing slash if not an existing directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Rewrite to use web.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ web.php?page=$1 [L]

You may not need to change the second rule if it's already working fine.

share|improve this answer
If I write the same code, it doesn't work. If I write before it: Options +FollowSymLinks RewriteEngine on When I write http://localhost/mysite/index It shows me a problem with a redirect loop. And if I write http://localhost/mysite/index/, it redirects me to: http://localhost/C:/UniServer/www/mysite/index. If I only write the first rule, it works for "index" but it redirects to the same with "index/". –  Nach Mar 10 '13 at 7:54

It worked adding this line

RewriteRule ^(.*)/$ /mysite/$1 [R,L]
share|improve this answer

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