Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

apache - Another mod_rewrite trailing slash question

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...