How following rewrite rule works in Apache?

I have running apache web (httpd) and application(tomcat) in the same host. And I would to auto point to a sitedown.html page whenever application(tomcat) server is not responding (incase of HTTP status code 502 and 503).

I saw below example on the few forum and would like to understand how does it works.

ErrorDocument 502 /sitedown.html
ErrorDocument 503 /sitedown.html
ErrorDocument 403 /404.html
ErrorDocument 404 /404.html

RewriteEngine On
RedirectMatch 301 ^/$ /apps/dashboard
RewriteCond %{DOCUMENT_ROOT}/maintenance_mode -f
RewriteCond %{REQUEST_FILENAME} !/sitedown.html
RewriteRule ^.*$    /sitedown.html [L]

Open in new window

beer9Asked:
Who is Participating?
 
gheistCommented:
You need to do a bit different way:
<Location /apps/dashboard>
 ProxyPass http://apps.i-mycompany.com/apps/dashboard
 ProxyPassReverse http://apps.i-mycompany.com/apps/dashboard
ProxyErrorOverride On
 ErrorDocument 404 "go away"
</Location>
0
 
gheistCommented:
Can you elaborate with ProxyPass sections leading to tomcat?
Basically proxy-passed requests are immune to rewrite by default
0
 
beer9Author Commented:
ProxyPass         /apps/dashboard http://apps.i-mycompany.com/apps/dashboard
ProxyPassReverse  /apps/dashboard http://apps.i-mycompany.com/apps/dashboard

Open in new window


Above is the ProxyPass rule in my config file
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
beer9Author Commented:
Hi Gheist, Thanks for your answer. I would like to understand using above example how can I  auto point to a sitedown.html page whenever application(tomcat) server is not responding (incase of HTTP status code 502 and 503).
0
 
gheistCommented:
Your syntax is correct with ErrorDocument-s
Missing Piece is ProxyErrorOverride to capture 404 in apache
And I suggest to reorganize httpd.conf so that you can host multiple sites with different error handling.
0
 
beer9Author Commented:
Hi Gheist, I would like to understand more when you say "Basically proxy-passed requests are immune to rewrite by default"

Now I came up with new config:

ProxyPass         /apps/dashboard http://apps.i-mycompany.com/apps/dashboard
ProxyPassReverse  /apps/dashboard http://apps.i-mycompany.com/apps/dashboard

ProxyPass         /apps/dashboard http://apps.i-mycompany.com/apps/myapp
ProxyPassReverse  /apps/dashboard http://apps.i-mycompany.com/apps/myapp

RewriteEngine On
RedirectMatch 301 ^/$ /apps/dashboard
RewriteCond %{DOCUMENT_ROOT}/maintenance_mode_dashboard -f
RewriteCond %{REQUEST_FILENAME} !/sitedown.html
RewriteRule ^.*$    /sitedown.html [L]

RedirectMatch 301 ^/$ /apps/myapp
RewriteCond %{DOCUMENT_ROOT}/maintenance_mode_myapp -f
RewriteCond %{REQUEST_FILENAME} !/sitedown.html
RewriteRule ^.*$    /sitedown.html [L]

Open in new window


so in DOCUMENT_ROOT folder if I have maintenance_mode_myapp file then any one accessing www.mycompany.com/apps/myapp then he would be getting/redirecting www.mycompany.com/sitedown.html page? Please help me understand if it doesn't works then why? Thanks in advance.
0
 
gheistCommented:
You need to set
 ProxyErrorOverride On
So that apache handles errors of mod_proxy.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.