Mobile app version of vmapp.org
Login or Join
Miguel251

: Getting problem in removing end slash from directory 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

@Miguel251

Posted in: #Htaccess

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$ [R=301]

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

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

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

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


Thanks

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Miguel251

1 Comments

Sorted by latest first Latest Oldest Best

 

@Speyer207

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme