Forum Moderators: phranque
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]
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?
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
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.)
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]