简体   繁体   English

另一个mod_rewrite尾随斜线问题

[英]Another mod_rewrite trailing slash question

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. 这有效 - 这意味着我可以使用http://www.site.com/news/http://www.site.com/news进入news页面,这就是我想要的。 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. 问题是,虽然http://www.site.com/news/工作正常,并且无声地重定向和所有有趣的东西, http://www.site.com/news/?action=news http://www.site.com/news明显被重定向到http://www.site.com/news/?action=news由于某种原因。 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. 他们都提出了相同的网站,但出于某种原因,如果我不使用尾随斜线,URL会发生变化并且看起来很讨厌。

Any ideas what's going on with this? 有什么想法吗? I have no other rules in my .hyaccess file. 我的.hyaccess文件中没有其他规则。 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. 我还要指出http://www.site.com/news/0http://www.site.com/news/0/不会遇到同样的问题。 Both of them redirect invisibly to http://www.site.com/?action=news&start=0 , which is what I want. 它们都无形地重定向到http://www.site.com/?action=news&start=0 ,这就是我想要的。 It only seems to be a problem with that third rule. 这似乎只是第三条规则的问题。

If it helps any, the site is on SourceForge.net. 如果它有帮助,该网站在SourceForge.net上。

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. 一个疯狂的猜测:有一个名为“news”的目录,并且自动Apache目录“添加一个尾部斜杠”重定向正在以一种奇怪的方式与你的RewriteRule进行交互。 If that's the case, 如果是这样的话,

DirectorySlash Off

may help. 可能有帮助。

Maybe MultiViews is causing this behavior. 也许MultiViews会导致这种行为。 Try to disable this option: 尝试禁用此选项:

Options -MultiViews

Another guess: remove the leading slash in the substitution. 另一个猜测:删除替换中的前导斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM