Link to home
Start Free TrialLog in
Avatar of geomouchet
geomouchet

asked on

Redirect domain to subdomain. Show domain in address bar.

I have a main domain: domain1.com and a subdomain: sub.domain1.com.  I have another domain: domain2.com.  I would like requests for www.domain2.com to go to sub.domain1.com, but have the browser address bar show www.domain2.com.  The .htaccess file below is close to what I want, except the address bar shows sub.domain1.com instead of www.domain2.com.  How can I fix this?
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteRule ^ http://sub.domain1.com[R,L]

Open in new window

Avatar of caterham_www
caterham_www
Flag of Germany image

Your subdomain is not connected to your main domain (e.g. a subdirectory of it)? If that's not the case, you'll need a reverse proxy:
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
# requires mod_proxy et al.
RewriteRule ^(.*) http://sub.domain1.com/$1 [P]

Open in new window

Avatar of geomouchet
geomouchet

ASKER

caterham_www: Thanks for your help.  I'm kind of lost with this htaccess stuff.  I tried your rewriterule, but it gives a 404 error.  If it makes a difference, at my host the main domain directory is /www/www and the subdomain is /www/sub
ASKER CERTIFIED SOLUTION
Avatar of geomouchet
geomouchet

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