views:

194

answers:

2

I am trying to get a maintenance page setup for a suburi deployment on Phusion Passenger for a rails app. All the documentation shows DocumentRoot ReWrite rules, which don't appear (don't think they should) rewrite on suburis. I tried hacking around on the ReWrite rules to point at the suburi, but I can't seem to get it to work. Has anyone been able to get a setup which works?

A: 

I am having exactly the same problem. Although I am using the before filter way, I actually hate this method.

update and answer

this will work if I have several sub-uris, the only missing thing here is that I can not set the header to 503, because ErrorDocument is rely on a static file which I can not determine where it is in runtime.

assume app1 and app2 is one of my sub-uri

RewriteEngine On
RewriteCond %{REQUEST_URI} !.(css|gif|jpg|png)$
RewriteCond %{DOCUMENT_ROOT}/$1/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^/([^/]+)(/|/.*)?$ /$1/system/maintenance.html [L]

RailsBaseURI /app1
RailsBaseURI /app2
boblu
Let me know if the above works for you, and I will flag it as the answer.
naven87
I finally had time to test your rewrite rule, and I found it will have problem if I have several sub-uri when applying your last rule. I modified it a little, and post it in my answer
boblu
A: 

So I finally had some time to work on this and found that you can actually use the mod_rewrite method of handling maintenance page with some tweaks. Remember that for sub-domains there is a symbolic link created in the root directory to public directory of the application. Now if the public directory includes the maintenance file (or in a sub-directory) you can wire up mod_rewrite to find it.

For example assume application is named app1, and maintenance.html file is stored in a subdirectory system in the public directory. Here are the lines in the apache config file and it does not appear to matter whether it is declared before or after the RailsBaseURI /app1 line

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/app1/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ /app1/system/maintenance.html [L]

RailsBaseURI /app1
naven87