I really new to htaccess and regular expressions, and I'm getting a little lost.
I have a small script that I got from a tutorial that basically removes the file extension and adds a trailing slash to the end if needs be.
This code works fine for files in my main directory. I have a couple files that are in sub directories though and it seems the rules aren't being carried through.Code:RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^([^/]+)/$ $1.php # Forces a trailing slash to be added RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ RewriteRule (.*)$ /$1/ [R=301,L]
so for files at example.com/file.php the mod rewrite works fine and it allows the url to be example.com/file/
but for files at example.com/sub/file.php if I try to use example.com/sub/file/ I get a 404 page.
I think I understand that the condition its checking against is only looking in the root, but I don't know enough to add in another condition or rule to check a sub directory as well.
any help would be greatly appreciated.



Reply With Quote

Bookmarks