Avatar of beer9
beer9
Flag for India asked on

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

Apache Web ServerJava App Servers

Avatar of undefined
Last Comment
gheist

8/22/2022 - Mon
gheist

Can you elaborate with ProxyPass sections leading to tomcat?
Basically proxy-passed requests are immune to rewrite by default
beer9

ASKER
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
ASKER CERTIFIED SOLUTION
gheist

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
beer9

ASKER
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).
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
gheist

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.
beer9

ASKER
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.
gheist

You need to set
 ProxyErrorOverride On
So that apache handles errors of mod_proxy.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.