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

this is my code but i tried many ways but it is not working and i am not able to remove the end slash from the directory

RewriteEngine On
RewriteBase /

# remove enter code here.php; use THE_REQUEST to prevent infinite loops
RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP
RewriteRule (.*)\.php$ $1 [R=301]

# remove index
RewriteRule (.*)/index$ $1/ [R=301]

# remove slash if not directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /$
RewriteRule (.*)/ $1 [R=301]

# add .php to access file, but don't redirect
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

# Remove trailing slashes
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]


share|improve this question

This will happen because you are removing the tailing slash and then expecting it to be added for directories, I don't think this will work and the work around would be to remove everything referring to adding a slash and use mod_autoindex.html

That way you can have /directory/index.html that will be processed without the tailing slash so this would look like /directory and still list your files as directory view. Quick and easy work around while maintaining the same URL structor of the rest of the site.

share|improve this answer

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.