Estou configurando um novo servidor Linux. Gostaria de redirecionar silenciosamente
www.domain.com/whatever
a www.domain.com/flows/default/whatever
, a menos que o fluxo seja especificado explicitamente, como
www.domain.com/flows/beta/whatever
Dentro da entrada VirtualHost do meu domínio, tenho o seguinte:
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>
Onde "domain.com" é meu domínio real obv.
Estas são as mesmas duas regras que eu sempre usei no passado, no entanto, algo não está funcionando agora. Qualquer URL modificado pela segunda regra exibe uma página 404 com uma mensagem como a seguinte:
The requested URL /cgi-sys/ea-php70/index.php was not found on this server.
Na metade do log de saída, está a seguinte linha:
init rewrite engine with requested uri /cgi-sys/ea-php70/index.php
Eu não sei o suficiente sobre como tudo funciona para entender porque o CGI / PHP está sendo envolvido no procedimento. Aqui está o log completo:
[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]
Portanto, a questão oficial é: por que meu redirecionamento não está funcionando e o que preciso fazer para corrigi-lo?
Deixe-me saber se você precisar de alguma outra informação. Obrigado pessoal.
UPDATE
A configuração é CentOS, cPanel, Apache 2.4, Evento MPM, PHP-FPM, PHP 7, suEXEC.
Ok, então adicionei RewriteCond %{REQUEST_URI} !^/cgi-sys/ [NC]
à segunda regra apenas para que funcione, e isso acontece agora. Eu ainda gostaria de saber o que está acontecendo internamente apenas para conhecimento pessoal, se alguém tiver uma ideia.
Tags mod-rewrite