我正在设置一个新的 Linux 服务器。我想静默重定向
www.domain.com/whatever
到www.domain.com/flows/default/whatever
除非明确指定流程,例如
www.domain.com/flows/beta/whatever
在我的域名的 VirtualHost 条目中,我有以下内容:
LogLevel error rewrite:trace6
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,NC,R=301]
RewriteCond %{REQUEST_URI} !^/flows/ [NC]
RewriteRule ^ /flows/default%{REQUEST_URI} [NC]
</IfModule>
其中“domain.com”是我的实际域名。
这两个规则和我过去一直使用的规则相同,但现在有些地方不太对劲。任何被第二条规则修改的 URL 都会出现 404 页面,并显示如下消息:
The requested URL /cgi-sys/ea-php70/index.php was not found on this server.
输出日志的中间部分有以下一行:
init rewrite engine with requested uri /cgi-sys/ea-php70/index.php
我不太了解一切工作方式,因此无法理解为什么 CGI/PHP 会参与到该过程中。以下是完整日志:
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] init rewrite engine with requested uri /index.php
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] applying pattern '^' to uri '/index.php'
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] RewriteCond: input='domain.com' pattern='^domain.com$' [NC] => matched
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] rewrite '/index.php' -> 'http://www.domain.com/index.php'
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] explicitly forcing redirect with http://www.domain.com/index.php
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] escaping http://www.domain.com/index.php for redirect
[domain.com/sid#6de4c962d30][rid#70829c002970/initial] redirect to http://www.domain.com/index.php [REDIRECT/301]
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] init rewrite engine with requested uri /index.php
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] applying pattern '^' to uri '/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] RewriteCond: input='www.domain.com' pattern='^domain.com$' [NC] => not-matched
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] applying pattern '^' to uri '/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] RewriteCond: input='/index.php' pattern='!^/flows/' [NC] => matched
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] rewrite '/index.php' -> '/flows/default/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] local path result: /flows/default/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] prefixed with document_root to /home/mario/public_html/flows/default/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c002970/initial] go-ahead with /home/mario/public_html/flows/default/index.php [OK]
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] init rewrite engine with requested uri /cgi-sys/ea-php70/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] applying pattern '^' to uri '/cgi-sys/ea-php70/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] RewriteCond: input='www.domain.com' pattern='^domain.com$' [NC] => not-matched
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] applying pattern '^' to uri '/cgi-sys/ea-php70/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] RewriteCond: input='/cgi-sys/ea-php70/index.php' pattern='!^/flows/' [NC] => matched
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] rewrite '/cgi-sys/ea-php70/index.php' -> '/flows/default/cgi-sys/ea-php70/index.php'
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] local path result: /flows/default/cgi-sys/ea-php70/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] prefixed with document_root to /home/mario/public_html/flows/default/cgi-sys/ea-php70/index.php
[www.domain.com/sid#6de4c962d30][rid#70829c00be58/initial/redir#1] go-ahead with /home/mario/public_html/flows/default/cgi-sys/ea-php70/index.php [OK]
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] init rewrite engine with requested uri /404.shtml
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] applying pattern '^' to uri '/404.shtml'
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] RewriteCond: input='www.domain.com' pattern='^domain.com$' [NC] => not-matched
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] applying pattern '^' to uri '/404.shtml'
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] RewriteCond: input='/404.shtml' pattern='!^/flows/' [NC] => matched
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] rewrite '/404.shtml' -> '/flows/default/404.shtml'
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] local path result: /flows/default/404.shtml
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] prefixed with document_root to /home/mario/public_html/flows/default/404.shtml
[www.domain.com/sid#6de4c962d30][rid#70829c00ff58/initial/redir#2] go-ahead with /home/mario/public_html/flows/default/404.shtml [OK]
所以官方的问题是,为什么我的重定向不起作用,我需要做什么来纠正它?
如果您需要任何其他信息,请告诉我。谢谢大家。
更新
配置是 CentOS、cPanel、Apache 2.4、MPM 事件、PHP-FPM、PHP 7、suEXEC。
好的,我添加了RewriteCond %{REQUEST_URI} !^/cgi-sys/ [NC]
第二条规则,让它工作起来,现在它确实工作了。如果有人有想法,我仍然想知道内部发生了什么,只是为了个人了解。