I am trying to configure an .htaccess file to reroute all urls to the nearest index subdirectory, like this:
http://example.com/admin/blah/test/whatever should stay in the address bar, but point to:
- http://example.com/admin/blah/test/whatever/index.php if it exists, otherwise:
- http://example.com/admin/blah/test/index.php if it exists, otherwise:
- http://example.com/admin/blah/index.php if it exists, otherwise:
- http://example.com/admin/index.php
If the url is that of an actual file, it should always go to that file. so http://example.com/admin/blah/file.css or http://example.com/admin/blah/item.inc should all still work if they exist, otherwise it should redirect to index.php in that folder, or nearest parent folder like shown above.
I'd also like to have this only affect a subfolder, if that's at all possible. In the above example, I'm assuming the .htaccess file would go in the /admin/ folder.
Update: Here's what currently works:
# No Directory Listings or trailing slashes Options -Multiviews -Indexes +FollowSymLinks <IfModule mod_rewrite.c> RewriteEngine On DirectorySlash Off # See if the current request is a directory containing an index file RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}/index.php -f RewriteRule ^(.*)/?$ $1/index.php [L,QSA] # if index.php doesn't exist in current dir then # forward to the parent directory of current REQUEST_URI RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}/$1$2/index.php !-f RewriteRule ^(.*?/)?([^/]+)/?$ $1 [L,QSA] </IfModule> This mostly works. If I type in http://example.com/admin?p=2 it resolves as expected, but if I use the URL http://example.com/admin/?p=2 it ALSO resolves, without explicitly removing the trailing slash.