請幫我在 mod_rewrite 中重定向 URL

請幫我在 mod_rewrite 中重定向 URL

我正在設定一個新的 Linux 伺服器。我想默默地重定向

www.domain.com/whateverwww.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」是我的實際網域 obv。

這也是我過去一直在使用的兩條規則,但是現在有些東西不起作用了。任何被第二條規則修改的 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 Event、PHP-FPM、PHP 7、suEXEC。

好的,所以我添加了RewriteCond %{REQUEST_URI} !^/cgi-sys/ [NC]第二條規則只是為了讓它起作用,現在它就起作用了。如果有人有想法,我仍然想知道內部發生了什麼,僅供個人了解。

相關內容