htaccess RewriteRule força fim de execução Apache 2.2

1

Oi eu tenho escrito algumas reescritas, mas pelo que eu posso dizer dos logs parece que as regras continuam em execução e assim, embora o resultado correto seja alcançado no meio da execução, a reescrita final está incorreta.

Idealmente, eu precisaria usar o [END] flag mas não posso atualizar o software do servidor que é o Apache 2.2, então vou ter que contornar isso.

Estou tentando reescrever "/ wedding? url = emily-and-john-2013" para "/ wedding / emily-and-john-2013".

Como estou usando o CodeIgniter, primeiro preciso reescrever "index.php / wedding / ..." para "/ wedding /...".

Aqui estão as regras que tenho até agora.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]

    #Sends requests for /wedding/{blahblahblah} to
    #/wedding?url={blahblahblah}
    RewriteRule ^index.php/wedding/([^_]*)$ index.php/wedding?url=$1 [L]
</IfModule>

Aqui estão os logs (ligeiramente higienizados, mas você tem a ideia):

 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/wedding -> SRV_PATH/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/wedding/emily-and-john-2013 -> wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'wedding/emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-f' => matched
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-d' => matched
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (2) [perdir SRV_PATH/] rewrite 'wedding/emily-and-john-2013' -> 'index.php/wedding/emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding/emily-and-john-2013 -> SRV_PATH/index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (5) strip matching prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (4) add subst prefix: index.php/wedding/emily-and-john-2013 -> /index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b93e1c68/initial] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding/emily-and-john-2013 [INTERNAL REDIRECT]
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'index.php/wedding/emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/index.php' pattern='!-f' => not-matched
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] applying pattern '^index.php/wedding/([^_]*)$' to uri 'index.php/wedding/emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (2) [perdir SRV_PATH/] rewrite 'index.php/wedding/emily-and-john-2013' -> 'index.php/wedding?url=emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) split uri=index.php/wedding?url=emily-and-john-2013 -> uri=index.php/wedding, args=url=emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding -> SRV_PATH/index.php/wedding
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (5) strip matching prefix: SRV_PATH/index.php/wedding -> index.php/wedding
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (4) add subst prefix: index.php/wedding -> /index.php/wedding
 [*/sid#b8f1e8f0][rid#b9174a78/initial/redir#1] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding [INTERNAL REDIRECT]
 [*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding
 [*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding -> index.php/wedding
 [*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'index.php/wedding'
 [*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/index.php' pattern='!-f' => not-matched
 [*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding
 [*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding -> index.php/wedding
 [*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (3) [perdir SRV_PATH/] applying pattern '^index.php/wedding/([^_]*)$' to uri 'index.php/wedding'
 [*/sid#b8f1e8f0][rid#b917e088/initial/redir#2] (1) [perdir SRV_PATH/] pass through SRV_PATH/index.php
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/wedding -> wedding
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'wedding'
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-f' => matched
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-d' => matched
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (2) [perdir SRV_PATH/] rewrite 'wedding' -> 'index.php/wedding'
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding -> SRV_PATH/index.php/wedding
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (5) strip matching prefix: SRV_PATH/index.php/wedding -> index.php/wedding
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (4) add subst prefix: index.php/wedding -> /index.php/wedding
 [*/sid#b8f1e8f0][rid#b93a1c80/subreq] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding [INTERNAL REDIRECT]

Note que na linha 19 o URL correto é mostrado! Infelizmente continua correndo depois disso e de alguma forma o resultado final não está correto.

Alguma idéia de como alterar as regras para obter o efeito desejado?

EDITAR

Acabei de perceber que, se eu definir o sinalizador [R] para um redirecionamento em vez de uma reescrita, o navegador acabará apontando para o URL correto. Não tenho certeza do rumo que tem em qualquer coisa.

EDIT 2

Com o sinalizador [NS] adicionado à regra index.php , aqui estão os registros:

 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/wedding -> SRV_PATH/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/wedding/emily-and-john-2013 -> wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'wedding/emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-f' => matched
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/wedding' pattern='!-d' => matched
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (2) [perdir SRV_PATH/] rewrite 'wedding/emily-and-john-2013' -> 'index.php/wedding/emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding/emily-and-john-2013 -> SRV_PATH/index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (5) strip matching prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (4) add subst prefix: index.php/wedding/emily-and-john-2013 -> /index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9174dd0/initial] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding/emily-and-john-2013 [INTERNAL REDIRECT]
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'index.php/wedding/emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/index.php' pattern='!-f' => not-matched
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding/emily-and-john-2013 -> index.php/wedding/emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] applying pattern '^index.php/wedding/([^_]*)$' to uri 'index.php/wedding/emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (2) [perdir SRV_PATH/] rewrite 'index.php/wedding/emily-and-john-2013' -> 'index.php/wedding?url=emily-and-john-2013'
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) split uri=index.php/wedding?url=emily-and-john-2013 -> uri=index.php/wedding, args=url=emily-and-john-2013
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (3) [perdir SRV_PATH/] add per-dir prefix: index.php/wedding -> SRV_PATH/index.php/wedding
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (2) [perdir SRV_PATH/] trying to replace prefix SRV_PATH/ with /
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (5) strip matching prefix: SRV_PATH/index.php/wedding -> index.php/wedding
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (4) add subst prefix: index.php/wedding -> /index.php/wedding
 [*/sid#b8f1e8f0][rid#b9157758/initial/redir#1] (1) [perdir SRV_PATH/] internal redirect with /index.php/wedding [INTERNAL REDIRECT]
 [*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding
 [*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding -> index.php/wedding
 [*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] applying pattern '^(.*)$' to uri 'index.php/wedding'
 [*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (4) [perdir SRV_PATH/] RewriteCond: input='SRV_PATH/index.php' pattern='!-f' => not-matched
 [*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] add path info postfix: SRV_PATH/index.php -> SRV_PATH/index.php/wedding
 [*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] strip per-dir prefix: SRV_PATH/index.php/wedding -> index.php/wedding
 [*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (3) [perdir SRV_PATH/] applying pattern '^index.php/wedding/([^_]*)$' to uri 'index.php/wedding'
 [*/sid#b8f1e8f0][rid#b9173fe8/initial/redir#2] (1) [perdir SRV_PATH/] pass through SRV_PATH/index.php
 [*/sid#b8f1e8f0][rid#b912c738/subreq] (1) [perdir SRV_PATH/] pass through SRV_PATH/wedding
    
por Josh 25.09.2013 / 16:50

1 resposta

1

Você pode remover essa regra do contexto <Directory> ou .htaccess ? A subseção passthrough parece ser o problema.

Se não, tente adicionar um sinalizador [NS] à regra index.php para impedir que ele atue nessa sub-requisição?

RewriteRule ^(.*)$ index.php/$1 [NS,L]
    
por 25.09.2013 / 17:46