O cenário: preciso redirecionar determinados URLs e reescrever outros URLs
Agora, depois de muito mexer, consigo fazer quase tudo funcionar
Se eu acertar o example.com
funciona normalmente e 200
Se eu atingir o example.com/testrea
, o texto de example.com/test11/ucm25685.htm
será exibido e 200
Se eu atingir example.com/retest111/totest11.htm
, o redirecionamento para example.com/test1/ucm12347.htm
acontecerá, no entanto, receberei um 403 Proibido
Como faço para parar o 403 Proibido? Acho que sei porque está acontecendo, mas não consigo descobrir como pará-lo. Se eu desabilitar a parte de reescrita, o redirecionamento funcionará e não exibirá o 403 proibido.
Por que o 403 Forbidden está acontecendo, como pode ser visto pelos logs, quando uma página é solicitada e não no mapa de exemplo RewriteMap (rewrite.dbm) Ele enviará /
. Qual eu acho que seria um índice ausente, no entanto, adicionando -Indexes
ao Options
não fez nenhuma alteração e /
tem um index.htm que é definido no vhost.
A questão é quando uma solicitação é feita, como não posso reescrever se a URL não estiver no arquivo de mapa de exemplo RewriteMap (rewrite.dbm)?
Ou existe uma maneira melhor de misturar os Rewrites e Redirects, lembrando que isso é somente para o POC em produção? Eu terei algumas centenas de Rewrites ou Redirects e os arquivos dbm serão atualizados conforme novas páginas forem movidas.
Regra de saída de alerta LogLevel de saída: trace3
example.com
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56079] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f697290/initial] init rewrite engine with requested uri /
[DATE] [rewrite:trace3] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56079] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f697290/initial] applying pattern '^(.*)' to uri '/'
[DATE] [rewrite:trace3] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56079] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f697290/initial] applying pattern '^(.*)' to uri '/'
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56079] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f697290/initial] rewrite '/' -> '/index.htm'
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56079] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f697290/initial] local path result: /index.htm
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56079] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f697290/initial] prefixed with document_root to /var/www/sites/me/index.htm
[DATE] [rewrite:trace1] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56079] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f697290/initial] go-ahead with /var/www/sites/me/index.htm [OK]
example.com/testrea
[DATE] [rewrite:trace2] [pid 10407] mod_rewrite.c(470): [client 55.66.77.88:56111] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f698700/initial] init rewrite engine with requested uri /testrea
[DATE] [rewrite:trace3] [pid 10407] mod_rewrite.c(470): [client 55.66.77.88:56111] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f698700/initial] applying pattern '^(.*)' to uri '/testrea'
[DATE] [rewrite:trace3] [pid 10407] mod_rewrite.c(470): [client 55.66.77.88:56111] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f698700/initial] applying pattern '^(.*)' to uri '/testrea'
[DATE] [rewrite:trace2] [pid 10407] mod_rewrite.c(470): [client 55.66.77.88:56111] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f698700/initial] rewrite '/testrea' -> '/test11/ucm25685.htm'
[DATE] [rewrite:trace2] [pid 10407] mod_rewrite.c(470): [client 55.66.77.88:56111] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f698700/initial] local path result: /test11/ucm25685.htm
[DATE] [rewrite:trace2] [pid 10407] mod_rewrite.c(470): [client 55.66.77.88:56111] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f698700/initial] prefixed with document_root to /var/www/sites/me/test11/ucm25685.htm
[DATE] [rewrite:trace1] [pid 10407] mod_rewrite.c(470): [client 55.66.77.88:56111] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f698700/initial] go-ahead with /var/www/sites/me/test11/ucm25685.htm [OK]
example.com/retest111/totest11.htm
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f69f2d0/initial] init rewrite engine with requested uri /retest111/totest11.htm
[DATE] [rewrite:trace3] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f69f2d0/initial] applying pattern '^(.*)' to uri '/retest111/totest11.htm'
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f69f2d0/initial] rewrite '/retest111/totest11.htm' -> '/test1/ucm12347.htm'
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f69f2d0/initial] explicitly forcing redirect with http://example.com/test1/ucm12347.htm
[DATE] [rewrite:trace1] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f69f2d0/initial] escaping http://example.com/test1/ucm12347.htm for redirect
[DATE] [rewrite:trace1] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f69f2d0/initial] redirect to http://example.com/test1/ucm12347.htm [REDIRECT/301]
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f691260/initial] init rewrite engine with requested uri /test1/ucm12347.htm
[DATE] [rewrite:trace3] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f691260/initial] applying pattern '^(.*)' to uri '/test1/ucm12347.htm'
[DATE] [rewrite:trace3] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f691260/initial] applying pattern '^(.*)' to uri '/test1/ucm12347.htm'
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f691260/initial] rewrite '/test1/ucm12347.htm' -> '/'
[DATE] [rewrite:trace2] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f691260/initial] local path result: /
[DATE] [rewrite:trace1] [pid 10412] mod_rewrite.c(470): [client 55.66.77.88:56126] 55.66.77.88 - - [example.com/sid#55ac8f2ead48][rid#55ac8f691260/initial] go-ahead with / [OK]
Layout atual do Webroot
test1/ucm12347.htm
test2/ucm23452.htm
test3/ucm34674.htm
test4/ucm43489.htm
test5/ucm10963.htm
test11/ucm25685.htm
test22/ucm87546.htm
test33/ucm32548.htm
test44/ucm95142.htm
test55/ucm56485.htm
/retest111/totest11.htm
/retest222/totest22.htm
/retest333/totest33.htm
/retest444/totest44.htm
/retest555/totest55.htm
2 Arquivos de texto que estão sendo convertidos em arquivos DB e DBM:
rewrite.txt
httxt2dbm -i rewrite.txt -o rewrite.dbm
/ index.htm
/testrea test11/ucm25685.htm
/testreb test22/ucm87546.htm
/testrec test33/ucm32548.htm
/testred test44/ucm95142.htm
/testree test55/ucm56485.htm
redirecionamentos.txt
httxt2dbm -f db -i redirects.txt -o redirects.db
/retest111/totest11.htm test1/ucm12347.htm
/retest222/totest22.htm test2/ucm23452.htm
/retest333/totest33.htm test3/ucm34674.htm
/retest444/totest44.htm test4/ucm43489.htm
/retest555/totest55.htm test5/ucm10963.htm
No httpd.conf eu tenho uma reescrita global
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteMap examplemap "dbm:/etc/httpd/conf/rewrite.dbm"
RewriteRule ^(.*) /${examplemap:$1}
</IfModule>
E um host virtual separado
<VirtualHost *:80>
DocumentRoot /var/www/sites/me
ServerName example.com
DirectoryIndex index.htm
ErrorDocument 404 /index.php
Options +FollowSymLinks
RewriteEngine On
RewriteOptions Inherit
RewriteMap redirects dbm=db:/etc/httpd/conf/redirects.db
RewriteCond ${redirects:$1} !=""
RewriteRule ^(.*) /${redirects:$1} [redirect=permanent,last]
</VirtualHost>