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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Acronis Data Cloud 7.8 Enhances Cyber Protection

A closer look at five essential enhancements that benefit end-users and help MSPs take their cloud data protection business further.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.