Pregunta

Currently, I have the following rule in my httpd.conf file to forward all requests from port 80 to port 8080 to be served by GlassFish app server:

<VirtualHost *:80>
    ServerAdmin admin@myserver.com
    ServerName myserver.com
    ProxyPreserveHost On

    # setup the proxy
    <Proxy *>
        Order allow,deny
        Allow from all
    </Proxy>
    ProxyPass / http://localhost:8080/
    ProxyPassReverse / http://localhost:8080/
</VirtualHost>

Now, I need to add a rule such that all requests to http://myserver.com/ will be forwarded to http://myserver.com/page/index.html and the URL should still appear to be http://myserver.com/ on the client's browser. I tried to add the following rules inside the above VirtualHost:

RewriteEngine On
RewriteRule http://myserver.com/ http://myserver.com/page/index.html

or

RewriteEngine On
RewriteRule ^/ http://myserver.com/page/index.html

or

RewriteEngine On
RewriteRule ^/index.html http://myserver.com/page/index.html

However, when I go to http://myserver.com/, the browser have this error: This webpage has a redirect loop. The 3rd rule can only work if I go to http://myserver.com/index.html.

I am a total noob at writing rules for Apache. Hence, I'd be very grateful if you could show me what I've done wrong here :).

UPDATE:

The following rule works perfectly:

RewriteEngine On
RewriteRule ^/$ /page/index.html [R]
¿Fue útil?

Solución

You need to add a $ indicating the end of the URI:

RewriteEngine On
RewriteRule ^/$ http://myserver.com/page/index.html

ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/

Without the $, the regex ^/ matches /page/index.html which will cause it to redirect again, and it'll match again, and redirect again, etc.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top