Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Basically I want to redirect all requests to my domain to a specific page. For example, redirect all requests to page X, unless you are already on page X, in which case you should just load it. But my solutions just create an infinite loop :/

I tried...

RewriteCond %{REQUEST_URI} !=/underconstruction.html
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !^/underconstruction.html
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

From what you described, you want a rewrite rule more like:

RewriteRule ^(.*)$ $LINK [L,R=301]

In other words, lose the $1. That's attaching the original URL to the new URL, which results in an infinite loop.

(I didn't verify the conditionals, but one of those should work, I think)

share|improve this answer
add comment

The problem with the examples above is that the RewriteRule lines do not redirect to to underconstruction.html, they redirect roughly to the same URL again (since $1 matches the (.*)).

This example will 301 redirect all URLs to "/underconstruction.html":

RewriteEngine On
RewriteCond %{REQUEST_URI} !=/underconstruction.html
RewriteRule ^ /underconstruction.html [R=301]

(which translates as "If URI is not /underconstruction.html, redirect to /underconstruction.html")

share|improve this answer
add comment

How about

<VirtualHost *:80>
   ...
   RedirectMatch !^/underconstruction.html http://yourdomain/underconstruction.html
   ...
</VirtualHost>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.