Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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]

Thanks

share|improve this question

1 Answer 1

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

 
discard

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.