beer9
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.
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]
ASKER
ProxyPass /apps/dashboard http://apps.i-mycompany.com/apps/dashboard
ProxyPassReverse /apps/dashboard http://apps.i-mycompany.com/apps/dashboard
Above is the ProxyPass rule in my config file
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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).
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.
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.
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:
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.
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]
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.
You need to set
ProxyErrorOverride On
So that apache handles errors of mod_proxy.
ProxyErrorOverride On
So that apache handles errors of mod_proxy.
Basically proxy-passed requests are immune to rewrite by default