另一个 mod_rewrite 尾部斜杠问题
我的 .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]
所有这些都以 /?
结尾,以检查可选的尾部斜杠。 这有效 - 这意味着我可以使用 http://www.site.com/news/
或 http://www.site.com/news
来访问news
页面,这就是我想要的。 问题是,虽然 http://www.site.com/news/
工作正常并且静默重定向以及所有有趣的东西,http://www.site.com/news由于某种原因,
明显重定向到 http://www.site.com/news/?action=news
。 他们都提出了相同的网站,但由于某种原因,如果我省略尾部斜杠,URL 就会发生变化并且看起来很糟糕。
有什么想法吗? 我的 .hyaccess
文件中没有其他规则。 我还要指出 http://www.site.com/news/0
和 http://www.site.com/news/0/
确实不会遇到同样的问题。 它们都无形地重定向到 http://www.site.com/?action=news&start=0
,这就是我想要的。 这似乎只是第三条规则的问题。
如果有帮助的话,该站点位于 SourceForge.net 上。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个疯狂的猜测:有一个名为“news”的目录,并且自动 Apache 目录“添加尾部斜杠”重定向正在启动并以一种奇怪的方式与您的 RewriteRule 交互。 如果是这样的话,
可能会有所帮助。
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,
may help.
也许
MultiViews
导致了这种情况行为。 尝试禁用此选项:另一种猜测:删除替换中的前导斜杠。
Maybe
MultiViews
is causing this behavior. Try to disable this option:Another guess: remove the leading slash in the substitution.