Forum Moderators: phranque
The site I'm working on uses a scheme whereby http://example.com/a/b/...(etc) becomes http://example.com/index.php/a/b/...(etc)
On top of this, allowing access to specific subdirectories, as such:
RewriteCond %{REQUEST_URI} !/phpmyadmin/ [NC]
RewriteRule ^(([^/]+/)*[^/]+)/$ /index.php/$1 [L]
The problem I have is with trailing slashes. As it stands, http://example.com/a/b/ works, but http://example.com/a/b doesn't.
My initial thought was to put another condition above this, checking for the trailing slash then redirecting if one isnt found. I assumed that something like this should work:
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(([^/]+/)*[^/]+)$ $1/ [R=302,L]
RewriteCond %{REQUEST_URI} !/phpmyadmin/ [NC]
RewriteRule ^(([^/]+/)*[^/]+)/$ /index.php/$1 [L]
But courtesy of Fiddler, I discovered I was sending myself into all sorts of infinite loops. Trying other methods sourced from Google brought similar results.
I don't know if maybe theres a way of writing it into the original Rewrite Rule to append the trailing slash as its adding the index.php?
A bit of info that may help:
- At present, the site won't go more than 4 layers deep. ie. http://example.com/a/b/c/d/ This may change, but I'll cross that bridge when I come to it ;)
- No urls should end in an extension, everything should appear as a directory in the url.
As I said, any help would be much appreciated. And I'll sleep better tonight. ;)
[edited by: jdMorgan at 10:55 pm (utc) on Sep. 13, 2007]
[edit reason] No URLs, please. [/edit]
# Externally redirect to add a trailing slash
# if missing except for for URLs starting with
# /phpmyadmin or containing index.php/
RewriteCond %{REQUEST_URI} !/$
RewriteCond $1 !^phpmyadmin/ [NC]
RewriteCond $1 !index\.php/
RewriteRule (.*) http://www.example.com/$1/ [R=[b]301[/b],L]
#
# Rewrite all URLs except for URLs starting with /phpmyadmin
# or containing index.php/ to index.php/path
RewriteCond $1 !^phpmyadmin/ [NC]
RewriteCond $1 !index\.php/
RewriteRule ^(([^/]+/)*[^/]+)/$ /index.php/$1 [L]
Jim