Mod 重写 localhost 工作正常,在 PHP QUERY_STRING 和 $_GET 为空的服务器上

发布于 12-26 16:48 字数 430 浏览 2 评论 0原文

我有一个奇怪的问题。我在本地主机上开发我的网站,然后将其分发到服务器端。大多数时候,这都按预期工作,但现在注意到一些奇怪的事情,无法找出问题所在。

在服务器上,所有 RewriteRule 都会重定向,但没有预期的查询。像这样的东西在本地主机上工作正常,但在服务器上却不行:

RewriteEngine On .... ....

RewriteRule .....

编辑:出于安全原因更改了条目,抱歉!

.... ....

有人知道发生了什么事吗?我错过了什么吗?为什么查询没有通过?是服务器配置吗?在互联网上找不到任何有关它的信息。

感谢您的评论。

编辑:下面的解决方案,第二条评论。与 apache 首先处理的内容有关。

I have a weird problem. I develop my sites on localhost and after that i distribute it server side. Most of the time this is working as expected but now notice something weird and cannot figure out what the problem is.

On the server all RewriteRule redirects but without expected queries. Something like this is working fine on localhost but not on the server:

RewriteEngine On
....
....

RewriteRule .....

EDIT: Changed entries for security reasons, sorry!

....
....

Does anybody knows what is going on? Do i miss something? Why are the queries not passed thru? Is it a server configuration? Cannot find anything about it on the internet.

Thank you for your comments.

EDIT: SOLUTION below, second comment. Has something to do with what apache handles first.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂牵梦绕锁你心扉 2025-01-02 16:48:46

@Erwinus,您讨论的“Perdir”功能是 Apache 中的标准功能,但尚未得到很好的理解。 Apache 将探测、打开并读取脚本文件名路径上的所有现有 .htaccess 文件。 (忽略很少选择的RewriteOptions继承追踪)它使用它发现的具有RewriteEngine On的最深的.htaccess文件。

因此,我与 Mario 的观点不同,恕我直言,几乎不可能让父目录重写规则来抢占子目录集——Apache 的默认操作是忽略父目录。我在这篇博客文章中进行了更详细的解释。

@Erwinus, the "Perdir" functionality that you discuss is standard in Apache but not well understood. Apache will probe for, then open and read all existing .htaccess files on the path to a script filename. (Ignoring the RewriteOptions inherit chase which is rarely chosen) it uses the deepest .htaccess file that it finds that has RewriteEngine On.

I would therefore differ from Mario's view in that IMHO its almost impossible to get a parent directories rewrite rules to preempt a child directory set -- the default action of Apache is to ignore the parent. I explain in a more detail in this blog article.

回忆凄美了谁 2025-01-02 16:48:46

这些东西几乎不可能调试。但是 mod_rewrite 提供了一项功能,您应该设置该功能来调查此问题:

RewriteLog /tmp/rewritelog.txt
RewriteLogLevel 2

RewriteLog指令不能在 .htaccess 中使用。您需要在虚拟主机或主服务器配置中声明它。如果2级别仍然不够,请尝试3

否则,我只是建议您尝试 RewriteBase,因为您似乎将不同的目录级别与您的规则相匹配。可能会再次在子目录 (streambutler/) 中重复您的规则。 Apache 的 mod_rewrite 很特殊,有时会忽略父目录中的它们。

These things are nearly impossible to debug. But mod_rewrite offers one feature that you should set up to investigate this:

RewriteLog /tmp/rewritelog.txt
RewriteLogLevel 2

The RewriteLog directive however cannot be used from .htaccess. You need to declare it in the vhost or main server configuration. If level 2 is still insufficient, then try 3.

Otherwise I'd just would advise you to try a RewriteBase, since you seem to match varying directory levels with your rules. Possibly repeat your rules in the subdirectories (streambutler/) again. Apaches mod_rewrite is peculiar and ignores them in the parent dir sometimes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文