4

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

| improve this answer | |
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")

| improve this answer | |
1

How about

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy