Redirect all traffic regardless of port or protocol to temporary page

apache-2.2maintenanceredirecttomcat6

I have a server with multiple domains. Both http (apache) traffic and http-alt (tomcat) traffic.

If/when I take the server down, I'd like to be able to redirect people to a temporary 'undergoing maintenance' page, regardless of their destination URL/port.

How can this be achieved? Do I need tomcat running on the secondary server or is there a way to catch all and redirect via some method I'm not aware of? I've tried simply forcing all 80/8080 traffic to the secondary server, but depending on the URL it doesn't resolve, and it never resolves when trying to access :8080/whatever. Any ideas?

EDIT (update): I have successfully achieved this catch all for any domain and anything port 80 traffic using _default_ vhost, but it's still not catching anything on 8080, even though I am specifying:

<VirtualHost _default_:*>
    DocumentRoot /var/www
    ServerName host
    ServerAlias *
    ErrorDocument 404 /index.html
</VirtualHost>

Anyone know why or how to?

EDIT (update 2): using tomcat's error-code

in /etc/tomcat/web.xml I added

<error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/index.html</location>
</error-page>

I am able to get it to work now for the root of tomcat http://domain.com:8080 but nothing for any general 404 like http://domain.com:8080/nonexistentpath

Any ideas? Thanks

Best Answer

As noted in my updates to the question and stated in the comments above:

To handle the port Apache (port 80) 404's, I used the following in the Apache config:

<VirtualHost _default_:*>
    DocumentRoot /var/www
    ServerName host
    ServerAlias *
    ErrorDocument 404 /index.html
</VirtualHost>

To handle them in Tomcat (8080, in my case), in /etc/tomcat/web.xml i added:

<error-page>
    <error-code>404</error-code>
    <location>/index.html</location>
</error-page>

The only other problem I came across is that the tomcat 404 would not display on IE. I ended up needing to add additional data to the page in form of comments to add some weight to the file for IE to display my custom page instead of it's own. How silly.

I hope this helps someone else, in the future.

Related Topic