另一个mod_rewrite的斜线问题 [英] Another mod_rewrite trailing slash question

查看:139
本文介绍了另一个mod_rewrite的斜线问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在的.htaccess 文件中的以下重写规则:

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]

所有然后用结束/?来检查可选尾随斜线。这工作 - 这意味着我可以使用 http://www.site.com/news/ http://www.site.com /新闻来获取到新闻页,这就是我想要的。现在的问题是,虽然 http://www.site.com/news/ 工作正常,并默默重定向和所有有趣的东西, HTTP: //www.site.com/news 有明显重定向到 http://www.site.com/news/?action=news 的某些原因。他们都拿出相同的网站,但由于某些原因,如果我离开了尾随斜线,该URL变化,看起来都讨厌的。

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.

任何想法是怎么回事这个?我在我的 .hyaccess 文件中没有其他规则。我还要指出的是, http://www.site.com/news/0 http://www.site.com/新闻/ 0 / 不要从同一个问题的困扰。他们都无形中重定向到 http://www.site.com/?action=news&start=0 ,这就是我想要的。它只是似乎与第三个规则的问题。

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.

如果它有助于任何,该网站是在SourceForge.net上。

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

推荐答案

一个大胆猜测:有一个名为新闻的目录,以及自动的Apache目录增加一个尾随斜线重定向踢在与交互您重写规则以不可思议的方式。如果是这样的话,

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

可能的帮助。

这篇关于另一个mod_rewrite的斜线问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆