Forum Moderators: phranque
I want to temporarily move this auth check out of teh way and replace the current .htaccess file with a new one that redirects the user to a specific shtml page while I update my site behind the scenes.
So far I have tried;
RewriteEngine On
RewriteBase /mysite/
RewriteCond ^.*$ !-f
RewriteCond ^.*$ !-d
RewriteRule ^(.*)$ /mysite/site_closed.shtml $1
This doesn't work - I get a server 500 error.
However, if I set the last line to;
RewriteRule ^(.*)$ /mysite/subdir/ $1
it seems to work?
Can anyone help here? Am I missing a key Apache config that is stopping the rewrite rule from redirecting to an .shtml file?
Thanks,
S.
It appears that you may be trying to "guess" this code, instead of designing it with the documentation [httpd.apache.org] at hand. Here's what your code says:
# If no file named "^.*$" exists
RewriteCond ^.*$ !-f
# and if no directory named "^.*$" exists
RewriteCond ^.*$ !-d
# then rewrite [b]all[/b] requests to /mysite/site_closed.shtml with an invalid RewriteRule 'flag' of $1
RewriteRule ^(.*)$ /mysite/site_closed.shtml $1
The RewriteConds don't do anything, since the result is always "true" and the rule will run.
What are the requirements, in terms of requested URLs that should be rewritten to the temporary page, and those that should not be rewritten to the temporary page?
Jim
The requirements are;
I have an old dir where there used to be live content. Rather than decommission the dir and sub dirs, as there are likely to be end users who still have legacy URLs to this old content, I want to place a .htaccess redirect to a simple static webpage in another location, in the highest level dir relative to the old content.
I'd also like to, if possible, exclude specific sub-dirs from the redirect. I have found a line of code that will apparently do this;
RewriteRule ^subdir/ - [L]
I'm assuming the first 2 lines of code (the RewriteCond lines) should be removed; from what you say the arguements stated will always be true and so they're pointless?
Big thanks, steep learning curve for me.
Smoosh
I'd also like to, if possible, exclude specific sub-dirs from the redirect. I have found a line of code that will apparently do this;RewriteRule ^subdir/ - [L]
That's one way to do it. It's not widely-useful though, because it tells mod_rewrite to 'quit' right there. Therefore, you can't have any other rules that perform other unrelated functions at any point in the file beyond this rule.
I'm assuming the first 2 lines of code (the RewriteCond lines) should be removed; from what you say the arguments stated will always be true and so they're pointless?
Something like this, located in /directory/.htaccess, would probably be simpler to implement and maintain:
# Do not redirect requests for site_closed.html
RewriteCond $1 !^site_closed\.html$
# Do not redirect requests for the following subdirectories
RewriteCond $1 !^retained_subdirectory1/
RewriteCond $1 !^retained_subdirectory2/
RewriteCond $1 !^retained_subdirectory3/
# Externally redirect all other requests to the site_closed page
RewriteRule (.*) http://www.example.com/site_closed.shtml [R=302,L]
"!" means NOT, and the RewriteConds are ANDed together by default.
Jim