另一个 mod_rewrite 尾部斜杠问题 [英] Another mod_rewrite trailing slash question

查看:30
本文介绍了另一个 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/news 来访问news 页面,这就是我想要的.问题是,虽然 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/0http://www.site.com/news/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.

推荐答案

疯狂猜测:有一个名为news"的目录,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天全站免登陆