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?

有帮助吗?

解决方案

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]

其他提示

Try to use a precondition:

RewriteCond %{REQUEST_URI} !^/construction.html
Redirect 302 / http://redsquirrelsoftware.co.uk/construction.html
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top