Forum Moderators: phranque

Message Too Old, No Replies

Recognize URI with or without trailing slash

How can I recognize URI with or without trailing slash?

         

asantos

6:10 am on Mar 12, 2006 (gmt 0)

10+ Year Member



I have this in my .htaccess:

**************
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^([^/]+)/$ /index.php?section=$1 [L]
**************

of course, if i call:
www.mysite.com/test/
resolves:
www.mysite.com/index.php?section=test

but when i call
www.mysite.com/test
resolves:
404 Not Found

....
I tried modifying the RewriteRule to:
RewriteRule ^([^/]+)/?$ /index.php?section=$1 [L]
(i inserted the '?' after the last '/') but that throws a 500 Internal Server Error.

Please help.

jdMorgan

6:00 pm on Mar 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you get a 500-Server Error response, it's a very good idea to look at your server error log, which will often tell you exactly what the problem is. It also helps us if you post that info.

However, I suspect you've put your server into a rewrite loop, because your code contains nothing to stop index.php from being rewritten again to index.php... and again and again, until the server reaches its maximum internal rewrite limit. It's fixed easily enough:


RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^index\.php$
RewriteRule ^([^/]+)/?$ /index.php?section=$1 [L]

Jim