Link to home
Start Free TrialLog in
Avatar of ptowndesign
ptowndesign

asked on

mod re-write to redirect specific subdomains

I've got two sites one.com & two.com

I'd like to use mod re-write to re-direct all subdomain traffic on one.com to two.com.

For instance, if someone typed in joe.one.com, it would redirect to joe.two.com

However, if they go to www.one.com or simply just one.com I'd like them to stay on one.com and not be re-directed.

Here's some code I tried to write - but I know that I'm way off the beaten path.  Any thoughts?

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*).(com|com/)
RewriteRule ^.*$ http://%1.two/.com{REQUEST_URI} [R=301,L]
Avatar of tuttlepc
tuttlepc
Flag of United States of America image

I would recommend handling this at the DNS level...  ie: www.zoneedit.com (free account starts with 5 credits) .... then you can redirect as necessary without straining your servers...

there's others too... easydns is another one that comes to mind...

from whichever standpoint...  as long as you can isolate x.domain.x.x.x.x with an ip address... with which you wish you direct traffic to... you should be able to manage all prefix domains to a particular ip regardless

and if your servers or sites are in disparate locations CNAME records come in handy too...

(once you setup a managed dns account, you will have to login to the registrar of the domain(s) in question and update the name servers to point to your new name servers)

however, this is a totally different approach than hard coding ....

if hard coding was my only option, i would do a page.redirect; once they landed at their predefined location..... (i'd have to check the syntax... ) on the html lvl...  log the visit etc, and pump that data back into your db


 
ASKER CERTIFIED SOLUTION
Avatar of ravenpl
ravenpl
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ptowndesign
ptowndesign

ASKER

ravenpl --

I tried the code, but it didn't seem to work.  
well... 1st off, i'm obviously not able to answer your question specifically... sorry... but hopefully at least i'm learning something..... because for the solution i provided would also require you to run an IIS (basic windows web server) to dictate where to send the requests inside your dmz.. on the specific (apache/etc server) .... oh well... i see where i'm lacking on the apache side