1


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 / https://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 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]
2
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).

  • thanks w3d. it is almost working. I can access now using: help-test.example.com/help/help but how to shrink it to: help-test.example.com/help thanks – wkg21 Mar 26 '15 at 12:19
  • Where exactly are you placing these directives? – MrWhite Mar 26 '15 at 12:21
  • just below SSL configuration before Proxypass – wkg21 Mar 26 '15 at 12:27
  • When it does redirect, does it redirect to /4-3/help or /help/4-3/help? You aren't setting the DocumentRoot in your VirtualHost - what is the document root? – MrWhite Mar 26 '15 at 12:40
  • 1
    changing to RewriteRule ^/help/ /4-3/$0 [R=301,L] worked. thanks a lot – wkg21 Mar 26 '15 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.