Проблемы с перезаписью apache



Я запускаю tomcat на centos6. Я пытаюсь настроить Apache в качестве интерфейса для tomcat, чтобы я мог получить доступ:

help-test.example.com:8080/4-3/help
help-test.example.com:8080/4-2/help
help-test.example.com:8080/4-1/help

Через:

help-test.example.com/4-3/help
help-test.example.com/4-2/help
help-test.example.com/4-1/help

С нижеприведенной конфигурацией apache он работает:

VirtualHost *:443>
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so

    ServerName help-test.example.com:443
    ServerAdmin [email protected]

    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
    SSLCertificateFile /etc/pki/tls/certs/localhost.crt
    SSLCertificateKeyFile /etc/pki/tls/private/localhost.key


    ProxyPass        / ajp://127.0.0.1:8009/
    ProxyPassReverse / ajp://127.0.0.1:8009/
    ProxyRequests Off
    ProxyPreserveHost On

     
        Order deny,allow
        Allow from all
     
     ErrorLog /var/log/httpd/error-ssl.log
     CustomLog /var/log/httpd/access-ssl.log combined
     RewriteLog "/var/log/httpd/rewrite-ssl.log"
     RewriteLogLevel 3
/VirtualHost>

VirtualHost *:80>
    ServerName  help-test.example.com
    Redirect / https://help-test.example.com
/VirtualHost>

Но еще одна вещь также должна быть сделана, когда я получу доступ:

help-test.example.com/help --> help-test.example.com/4-3/help

Я попытался добавить:

   RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/help/
    RewriteRule (.*) /4-3/help [L,NE,R]

Получение ошибки: На этой веб-странице есть цикл перенаправления

192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab202a8/initial] (2) init rewrite engine with requested uri /4-3/help
192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab202a8/initial] (3) applying pattern '(help)' to uri '/4-3/help'
192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab202a8/initial] (2) rewrite '/4-3/help' -> '/4-3/help'
192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab202a8/initial] (2) explicitly forcing redirect with https://help-test.example.com/4-3/help
192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab202a8/initial] (1) redirect to https://help-test.example.com/4-3/help [REDIRECT/302]
192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab0c308/initial] (2) init rewrite engine with requested uri /4-3/help
192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab0c308/initial] (3) applying pattern '(help)' to uri '/4-3/help'
192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab0c308/initial] (2) rewrite '/4-3/help' -> '/4-3/help'
192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab0c308/initial] (2) explicitly forcing redirect with https://help-test.example.com/4-3/help
192.168.1.40 - - [26/Mar/2015:10:13:26 +0000] [help-test.example.com/sid#7f89baa41700][rid#7f89bab0c308/initial] (1) redirect to https://help-test.example.com/4-3/help [REDIRECT/302]
Author: John Conde, 2015-03-26

1 answers

RewriteCond %{REQUEST_URI} !^/help/
RewriteRule (.*) /4-3/help [L,NE,R]

Вы получаете цикл перенаправления здесь, потому что вы говорите, что если URL-адрес не /help/ затем перенаправьте на /4-3/help (и т.д., и т.д.,...). Вам нужно изменить логику и перенаправлять только тогда, когда она /help/.

Изменить на...

RewriteRule ^/?help$ /4-3/help [R,L]

ПРИМЕЧАНИЕ: Это временное (302) перенаправление. Измените R на R=301, чтобы сделать его постоянным.

РЕДАКТИРОВАТЬ: Похоже, что было что-то, что добавляло завершающую косую черту к запросу перед обработкой перезаписи, поэтому шаблон RewriteRule необходимо было изменить на ^/help/$ (? был опущен, так как директива применяется непосредственно в конфигурации сервера).

 2
Author: MrWhite, 2015-03-26 14:26:13