7

我需要将/admin/page/createURL 重写为/backend/www/index.php/page/create,所以我使用下一个 Apache 重写规则和条件:

RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !backend\/www

RewriteRule admin\/(.*)$ backend/www/index.php/$1 [NS,L]

但是,检查重写日志,我看到 Apache 正确地重写了 URL,但最后它考虑到/page/create不匹配任何条件的 URL 执行了额外的重写,所以它失败并且我收到“未指定输入文件”。错误。

如何防止 Apache 执行额外的重写?我使用了NS标志和RewriteCond %{IS_SUBREQ} f条件,它还执行子请求。

谢谢!

80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (2) init rewrite engine with requested uri /admin/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (1) pass through /admin/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] add path info postfix: /home/daniloaz/dev.daniloaz.com/httpdocs/admin -> /home/daniloaz/dev.daniloaz.com/httpdocs/admin/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] strip per-dir prefix: /home/daniloaz/dev.daniloaz.com/httpdocs/admin/page/create -> admin/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] applying pattern 'admin\/(.*)$' to uri 'admin/page/create'
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='/admin/page/create' pattern='!-f' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='/admin/page/create' pattern='!-d' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='/admin/page/create' pattern='!backend\/www' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='/admin/page/create' pattern='((admin\/(.*)$)|(admin$))' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='false' pattern='f' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (2) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] rewrite 'admin/page/create' -> 'backend/www/index.php/page/create'
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] add per-dir prefix: backend/www/index.php/page/create -> /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (2) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] strip document_root prefix: /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php/page/create -> /backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (1) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] internal redirect with /backend/www/index.php/page/create [INTERNAL REDIRECT]
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (2) init rewrite engine with requested uri /backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (1) pass through /backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] add path info postfix: /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php -> /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] strip per-dir prefix: /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php/page/create -> backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] applying pattern 'admin\/(.*)$' to uri 'backend/www/index.php/page/create'
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (1) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] pass through /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a4ce60/subreq] (2) init rewrite engine with requested uri /page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a4ce60/subreq] (1) pass through /page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a4ce60/subreq] (1) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] pass through /home/daniloaz/dev.daniloaz.com/httpdocs/page
4

2 回答 2

11

好吧,我终于使用解决方法解决了这个问题。首先我尝试了这些解决方案,但子请求一次又一次地执行,重写和以前一样失败。

使用 mod_rewrite,如果您将规则放在 .htaccess 或全局配置(httpd.conf、Virtualhost 配置等)中,则存在细微差别。子请求是其中的区别之一。只需将我上面提到的相同规则放在 Virtualhost 配置文件中而不是 .htaccess 和子查询停止,一切都开始像魅力一样工作。

我推荐这篇有用的帖子,以便在尝试解决任何与之相关的问题之前充分了解 mod_rewrite 的内部结构:http: //net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/

于 2013-06-15T15:02:20.600 回答
0

我只是想在这里放弃我的经验,以防有人达到我所做的相同点:

我有同样的问题。我尝试了每一个答案。每一个解决方案。达到我可以说“我真的完全理解重写引擎”的水平。但没有任何效果。我的 URL 仍在更改并显示查询字符串。
在某个时刻,我说:“这很可能是不可能的。一定是别的东西”。然后我尝试使用 WGET 而不是浏览器 (firefox) 获取 URL。我做了:

wget -qSO http://MY-THING

然后我意识到服务器上没有任何东西说我在浏览器地址栏中看到的 URL。更好的是,日志文件中没有任何内容!

那么......它如何以及为什么会改变?显而易见的答案是“浏览器”我尝试了另一个浏览器(chrome)并且可以工作!所以我所做的就是用“忘记这个网站”选项来清理历史,每个人都很高兴。

现在我不知道我什么时候修好的。可能是 -Multiviews 的东西,或者规则的标志,或者 INTERNAL REDIRECT 部分......我真的不知道。但可能没有解决方案。

于 2018-05-30T15:16:51.700 回答