Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Using .htaccess to redirect different users

Simple way to send different groups of visitors to different places?

5:14 pm on Aug 2, 2002 (gmt 0)

Preferred Member

10+ Year Member

joined:July 20, 2001
votes: 0

Server things are pretty much beyond my knowledge, but I have learned to do a few simple things with .htaccess thanks to many of the helpful people here. What I'm now wondering is whether I can use .htaccess to direct visitors to different places depending upon the visitors' addresses. Example: anyone visiting my site from office1.mysite.com will be sent to "newoffice1", anyone visiting from office2.mysite.com will be sent to "newoffice2", and anyone visiting from any other address will be sent to "mainpage".

I suppose this is technically an example of cloaking, yes? I'm not using it for any nefarious purposes; I just want different groups of (human) users to be properly sent to new locations automatically.

One thing I have learned to do is to use the deny command to redirect someone coming from a particular site. If I put this in my .htaccess:

<Limit GET POST>
order allow,deny
allow from all
deny from office1.mysite.com

the "deny" will generate a 303 error, and I can put:

ErrorDocument 403 http:// newoffice1.mysite.com

and everyone coming from office1.mysite.com will be sent to newoffice1.

But is there a way to have more than one such redirect going to different places?

8:31 pm on Aug 2, 2002 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
votes: 0


IF you have access permission for mod_rewrite, it's easy to implement the redirect.

But your queston isn't clear... Are you giving these groups different URLs, each beginning with
a different subdomain on your site, and asking them to enter there? Or do you want to detect
their host name or IP address, and redirect based on that? Either way, you can do it, but the
details vary.

You example where you say "coming from office1.mysite.com" is what's got me confused, since this
is part of your domain, and does not indicate where the user is really coming from.

How about giving us a nice neat map with at least three examples in this format:
(Note: The underscores are just used to try to keep these columns lined up)

Visitor_From ____ Where_does_he_enter_your_site ______ Where_to_send_him

www.yahoo.com _ [mydomain.com...] __ [mydomain.com...]
www.yahoo.com _ [mydomain.com...] _______ [mydomain.com...]
www.google.com _ [mydomain.com...] __ [www...]
www.google.com _ [mydomain.com...] ______ [www...]
-others- _______ [mydomain.com...] __ [mydomain.com...]
-others- _______ [mydomain.com...] ______ [mydomain.com...]
-others- _______ [spcl.mydomain.com...] ___ [mydomain.com...]

Whipping up the rewrite rules is the easy part - defining the problem clearly is hard... :)