views:

1341

answers:

2

I have the following rewrite rules in my .htaccess file:

RewriteEngine on
RewriteRule ^news/([0-9]+)/?$ /?action=news&start=$1 [L]
RewriteRule ^man/([a-zA-Z0-9_]+)/?$ /?action=man&page=$1 [L]
RewriteRule ^([a-zA-Z0-9_]+)/?$ /?action=$1 [L]

All of then end with a /? to check for an optional trailing slash. This works - it means I can use either http://www.site.com/news/ or http://www.site.com/news to get to the news page, which is what I want. The problem is that, while http://www.site.com/news/ works fine and redirects silently and all that fun stuff, http://www.site.com/news is visibly redirected to http://www.site.com/news/?action=news for some reason. They both come up with the same site, but for some reason if I leave off the trailing slash, the URL changes and looks all nasty.

Any ideas what's going on with this? I have no other rules in my .hyaccess file. I'll also point out that http://www.site.com/news/0 and http://www.site.com/news/0/ do not suffer from the same problem. Both of them redirect invisibly to http://www.site.com/?action=news&start=0, which is what I want. It only seems to be a problem with that third rule.

If it helps any, the site is on SourceForge.net.

A: 

Maybe MultiViews is causing this behavior. Try to disable this option:

Options -MultiViews


Another guess: remove the leading slash in the substitution.

Gumbo
+2  A: 

A wild guess: there is a directory named "news", and the the automatic Apache directory "add a trailing slash" redirect is kicking in and interacting with your RewriteRule in a weird way. If that's the case,

DirectorySlash Off

may help.

Miles
Awesome! Thank you. I'm not sure why this happens, but Apache is a complex program and I'm willing to write it off as fixed now.
Chris Lutz