Question

I'm trying to add a rule into my .htaccess file so that if I am changing my website at all, it will redirect the user to an "under construction" page when they try to access my site.

I'm using:

# SITE UNDER CONSTRUCTION REDIRECT
Redirect 302 / http://redsquirrelsoftware.co.uk/construction.html

But this then sends me to http://redsquirrelsoftware.co.uk/construction.htmlconstruction.htmlconstruction.htmlconstruction.htmlconstruction.htmlconstruction.htmlconstruction.htmlconstruction.htmlconstruction.htmlconstruction.htmlconstruction.html and I obviously get a 404 error.

How do I stop the recursive tail on the web address?

Was it helpful?

Solution

Redirect is a mod_alias directive that can't be mixed with mod_rewrite directives, so to prevent the loop you should use only mod_rewrite directives like this:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !construction\.html   [NC]
RewriteCond %{REQUEST_URI} !folder_to_exclude    [NC]
RewriteRule .*           /construction.html      [R=301,L]

This answer assumes /construction.html page is in the same domain. If it isn't, replace:

RewriteRule .*             /construction.html         [R=301,L]

with

RewriteRule .*   http://new_domain/construction.html  [R=301,L]

OTHER TIPS

Try to use a precondition:

RewriteCond %{REQUEST_URI} !^/construction.html
Redirect 302 / http://redsquirrelsoftware.co.uk/construction.html
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top