Forum Moderators: phranque

Message Too Old, No Replies

Redirect Based On Domain

         

Nitro7

3:20 pm on Jul 11, 2002 (gmt 0)



Hello,
I am trying to figure out a way if a certain person trys to come to my website say from example.com or from a certain Class C they will get redirected to another page. I am assuming I should be able to do this with a .htaccess file using rewrite, but have been unsuccessful at all attempts so far.

Regards,
Clint

jdMorgan

9:41 pm on Jul 11, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteEngine On
RewriteCond %{REMOTE_HOST} ^example.com$ [OR]
RewriteCond %{REMOTE_ADDR} ^12\.34\.56\.78$
RewriteRule .* [sendumhere.com...] [R=301,L]

Also, you can simply return a code of 403 Forbidden to this user by changing the
rule to

RewriteRule .* - [F,L]

If you are putting this redirect on a "professional" site, that is the preferred
approach.

I'm not sure if the above is what you want when you say your unwelcome visitor
"comes from" example.com or a certain IP address; If you meant "clicks on a
link on example.com to get to my site", then you would use

RewriteCond %{HTTP_REFERER} ^example.com$

Note also that this covers "example.com" only. If you want www.example.com, then
you need

RewriteCond %{HTTP_REFERER} ^www.example.com$

or you could cover both with

RewriteCond %{HTTP_REFERER} example.com$

(no leading text anchor)

Note the [OR] at the end of the first RewriteCond. The default behavior of
mod_rewrite is to "and" all RewriteCond lines together, and only perform the
rewrite if ALL conditions are met.

Be careful with mod_rewrite - One typo may lock all of your users out - even
yourself. You must have ftp access to recover from such a problem. Short of
locking evryone out, you may unintentionally lock out just some users or lock
all users out of just some pages. So, make sure to test your site immediately
after changing anything in .htaccess! Then watch your error and access logs
like a hawk for at least few hours.

Treat .htaccess and mod_rewrite like a dangerous weapon - crucial to survival
in trained hands, dangerous to survival of the careless.

For more authoritative details as well as more warnings about the power of
mod_rewrite, check out

[httpd.apache.org...]

Hope this helps,
Jim

Nitro7

12:13 am on Jul 12, 2002 (gmt 0)



Jim,
Thanks that was the exact thing I needed. I have been researching this most of the day.

It is good to know I was on the right path using the rewrite engine and htaccess.

I am off now to study all I can about rewrite.

Regards,
Clint