简体   繁体   中英

Maintenance page forwarding with htaccess does not work for proxied material

I have scoured the internet and am at a loss as to why my maintenance page redirect and rewrite rules do not work for any proxied material or anything that is coming across through https.

I am using an Apache 2.2.3 server with tomcat 6.0.24 installed on it.

I have the following htaccess file:

Options +FollowSymlinks
RewriteCond %{REQUEST_URI} !/maintenance.html
RewriteCond %{REQUEST_URI} !/images/(.*)$
RewriteCond %{REQUEST_URI} !/scripts/(.*)$
RewriteCond %{REQUEST_URI} !/styles/(.*)$

RewriteCond %{REMOTE_ADDR) !^123.456.789.100

RewriteRule $ /maintenance.html [R=302,L]

It redirects all of my http pages to the maintenance page and all of my images, scripts, and styles work properly. However, it is not redirecting any https pages which are proxied from another machine.

So http://mypage.com/documents redirects to maintenance where as https://mypage.com/users does not redirect.

Unfortunately users is a proxied service that lives on a backend server whereas documents is a static page on the front end server.

Is there a way to force proxied and/or https material to be redirected as well? Or am I able to disable mod_proxy in my htaccess file so that nothing gets proxied?

  • Check your SSL virtualhost is reading .htaccess files ( AllowOverride None directive).
  • Avoid .htaccess file like plague. It's a dynamic configuration file. Rest of the configuration (in apache files) is static, makes a big difference in performances. But it's unrelated :-)
  • Some directives takes precedences on others, there is a priority in the order of execution . And in this documentation link you can see any Proxy directive is read before any Directory directive (and a .htaccess is a sub-sub-sub directory directive). So If your proxy is not handled by a mod-rewrite P tag in a .htaccess (what a bad idea anyway) it's applied before and chances are your .htaccess is never read (you are asking for a proxy, there is no local file to read, so Apache has no local directory to read, so apache do not need to parse all existing .htaccess files from a non-existent directory and all his parents)

On solution, if you can edit real configuration files, is to use a redirection in the VirtualHost level, not in a Directory (or .htaccess) or Location. So that it will be always applied:

ErrorDocument 503 /htdocs/err/maintenance.html
## uncomment below to enter maintenance mode
RedirectMatch 503 ^/(?!err/|images/|scripts/)

I usually use a simplier form with only elements in /err subdirectory, and redirecting everything not in this subdirectory to a 503 error. The 503 is then handled by the maintenance page in this err subdirectory. Here I have added the images/ and scripts/ subdirectories as well, did not test the expression but it should work, I think.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM