Mobile app version of vmapp.org
Login or Join
Murphy175

: Problems with apache rewrite I am running tomcat on centos6. I'm trying to configure Apache as a front end to tomcat so I could access: help-test.example.com:8080/4-3/help help-test.example.com:8080/4-2/help

@Murphy175

Posted in: #Apache #ModRewrite

I am running tomcat on centos6. I'm trying to configure Apache as a front end to tomcat so I could access:

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

via:

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

with below apache configuration it is working:

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 webmaster@example.com

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 / help-test.example.com /VirtualHost>

but one more thing needs also to be done when I access :

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

I have tried to add:

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

getting an error:
This web page has a redirect loop

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 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 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 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 help-test.example.com/4-3/help [REDIRECT/302]

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Murphy175

1 Comments

Sorted by latest first Latest Oldest Best

 

@Alves908

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


You are getting a redirect loop here because you are saying that if the URL is not /help/ then redirect to /4-3/help (etc, etc, ...). You need to reverse the logic and only redirect when it is /help/.

Change to...

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


NB: This is a temporary (302) redirect. Change R to R=301 to make it permanent.

EDIT: There appeared to be something that was appending a trailing slash to the request before the rewrite was processed, so the RewriteRule pattern needed to be changed to ^/help/$ (the ? was omitted since the directive is being applied directly in the server config).

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme