I have the following rewrite rules in my .htaccess
file:
我的.htaccess文件中有以下重写规则:
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.
所有这些都以/?结尾检查可选的尾部斜杠。这有效 - 这意味着我可以使用http://www.site.com/news/或http://www.site.com/news进入新闻页面,这就是我想要的。问题是,虽然http://www.site.com/news/工作正常,并且无声地重定向和所有有趣的东西,http://www.site.com/news明显重定向到http:// www。 site.com/news/?action=news由于某种原因。他们都提出了相同的网站,但出于某种原因,如果我不使用尾随斜线,网址会发生变化并且看起来很糟糕。
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.
有什么想法吗?我的.hyaccess文件中没有其他规则。我还要指出http://www.site.com/news/0和http://www.site.com/news/0/不会遇到同样的问题。它们都无形地重定向到http://www.site.com/?action=news&start=0,这就是我想要的。这似乎只是第三条规则的问题。
If it helps any, the site is on SourceForge.net.
如果它有帮助,该网站在SourceForge.net上。
2 个解决方案
#1
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,
一个疯狂的猜测:有一个名为“news”的目录,并且自动Apache目录“添加一个尾部斜杠”重定向正在以一种奇怪的方式与你的RewriteRule进行交互。如果是这样的话,
DirectorySlash Off
may help.
#2
Maybe MultiViews
is causing this behavior. Try to disable this option:
也许MultiViews会导致这种行为。尝试禁用此选项:
Options -MultiViews
Another guess: remove the leading slash in the substitution.
另一个猜测:删除替换中的前导斜杠。
#1
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,
一个疯狂的猜测:有一个名为“news”的目录,并且自动Apache目录“添加一个尾部斜杠”重定向正在以一种奇怪的方式与你的RewriteRule进行交互。如果是这样的话,
DirectorySlash Off
may help.
#2
Maybe MultiViews
is causing this behavior. Try to disable this option:
也许MultiViews会导致这种行为。尝试禁用此选项:
Options -MultiViews
Another guess: remove the leading slash in the substitution.
另一个猜测:删除替换中的前导斜杠。