Q:

How to make an .htaccess wildcard mod_rewrite condition for redirecting one URL to another if file doesn't exist while including the root?

I have this setup:

http://www.example.com
http://www2.example.com

Here's the rules I need to meet:

If http://www.example.com/test doesn't exist, redirect to http://www2.example.com/test
If you visit http://www.example.com or http://www.example.com/, don't redirect (index.html exists)
If you visit http://www.example.com/special redirect to http://bing.com
If you visit http://www.example.com/special2 redirect to http://google.com

Here's what I have so far:
<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /
RewriteEngine on

Redirect 301 /special http://bing.com
Redirect 301 /special2 http://google.com

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://www2.example.org/$1 [L,R=301]

</IfModule>

The problem is, when I visit http://www.example.com it's redirecting me to http://www2.example.com.

A:

Try making your last rule to:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ http://www2.example.org/$1 [L,R=301]

