5

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]

3 Answers 3

1

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)

12

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")

1

How about

<VirtualHost *:80>
   ...
   RedirectMatch !^/underconstruction.html http://yourdomain/underconstruction.html
   ...
</VirtualHost>

You must log in to answer this question.