Forum Moderators: phranque

Message Too Old, No Replies

Prohibiting all access during site maintenance

works except for one directory

         

dhiggerdhigger

5:23 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



I have used the following to prohibit all access to my website during site maintenance, in the root .htaccess:

RewriteEngine on
Options +FollowSymLinks
RewriteBase /
# allow my IP, and the W3 validator
RewriteCond %{REMOTE_HOST}!^123\.456\.123\.456
RewriteCond %{REMOTE_HOST}!^validator\.w3\.org$
RewriteCond %{REQUEST_URI}!/other/temporarily-offline\.php$
RewriteRule .* /other/temporarily-offline.php [R=302,L]

Then the temporarily-offline.php page serves up something friendly, with a 503 Service Unavailable header.

It works for every page except for my (Wordpress) blog pages, which are at www.example.com/blog/

The .htaccess in /blog has this:


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule . /blog/index.php [L]
</IfModule>

Why are the /blog pages still accessible?

jdMorgan

10:36 pm on Nov 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It depends on how the blog was installed, and whether RewriteOptions inherit is set by the server config file.

If the blog was installed using a directive in mod_alias, then it's possible that requests will be sent to /blog before mod_rewrite even has a chance to run.

If not, but if RewriteOptions inherit is not set, then your rules won't be applied to subdirectories -- although I think you would have noticed this previously, since it's a "larger" problem.

Also, there is no need for an external 302 redirect to /other/temporarily-offline.php; Just use an internal rewrite, and then let the script return the 503-Service Unavailable server response header with that page.

Jim

dhiggerdhigger

11:21 pm on Nov 14, 2007 (gmt 0)

10+ Year Member



My .htaccess commands do cascade to child directories (usually), so perhaps RewriteOptions inherit is set already.

Curious.

Also by "internal redirect" do you mean something like


RewriteRule .* /other/temporarily-offline.php [R=503,L]
ErrorDocument 503 /other/temporarily-offline.php

With these commands, the browser URL doesn't change...so is it an internal redirect? (Actually I'm not sure, because it seems that the RewriteRule needs a relative URL, even though it's set with the 503 error code. That is to say, I couldn't leave the "/other/temporarily-offline.php" out of the RewriteRule, even though (I am assuming) it's redundant.)

jdMorgan

11:31 pm on Nov 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



We're at cross-purposes here...

Just use an internal rewrite, and then let the script return the 503-Service Unavailable server response header with that page.

Having an ErrorDocument declaration does not invoke a 503 response. You have to send the 503 header with your "unavailable" page -- either by letting the script write the response header, or by using mod_headers directives inside a <FilesMatch> container to do so.

Jim

[edited by: jdMorgan at 12:17 am (utc) on Nov. 15, 2007]