Presumably you have multiple domains on this account?
To redirect either example.com/
or example.com/another-url/
to example.com/page.html
then you can do something like the following in .htaccess
:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(|another-url/)$ /page.html [R=302,L]
The HTTP_HOST
server variable contains the host being requested. The pattern ^(|another-url/)$
matches either an empty URL-path (ie. the document root) or another-url/
(less the directory prefix).
RewriteCond %{REMOTE_ADDR} !^one.domain.com
RewriteRule .* /page.html [R=302,L]
This would have redirected everything to /page.html
. The problems with your original directives...
REMOTE_ADDR
is the client IP address making the request, not the host being requested.
- The
!
prefix on the CondPattern negates the regex. So, in the above it matches when the REMOTE_ADDR
is not example.com
. (Always true.)
- The
.*
RewriteRule
pattern matches every URL!