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]
ptowndesignAsked:
Who is Participating?
 
ravenplConnect With a Mentor Commented:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.one\.com
RewriteRule .* http://%1.two.com%{REQUEST_URI} [R=301,L]
0
 
tuttlepcCommented:
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


 
0
 
ptowndesignAuthor Commented:
ravenpl --

I tried the code, but it didn't seem to work.  
0
 
tuttlepcCommented:
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
0
All Courses

From novice to tech pro — start learning today.