Redirect domain to subdomain. Show domain in address bar.

Posted on 2009-07-05
Last Modified: 2012-08-13
I have a main domain: and a subdomain:  I have another domain:  I would like requests for to go to, but have the browser address bar show  The .htaccess file below is close to what I want, except the address bar shows instead of  How can I fix this?
RewriteEngine On

Options +FollowSymlinks

RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]

RewriteRule ^[R,L]

Open in new window

Question by:geomouchet
  • 2
LVL 27

Expert Comment

ID: 24783211
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 ^(.*)$1 [P]

Open in new window


Author Comment

ID: 24784949
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

Accepted Solution

geomouchet earned 0 total points
ID: 25219381
This is what actually worked:
RewriteEngine On

Options +FollowSymlinks -Indexes

RewriteOptions MaxRedirects=10

RewriteBase /

RewriteCond %{HTTP_HOST} ^www.secondary_domain.* 

RewriteCond %{REQUEST_URI} !/subdirectory/

RewriteRule ^(.*)$ /subdirectory/$1

RewriteCond %{HTTP_HOST} ^secondary_domain.*

RewriteCond %{REQUEST_URI} !/subdirectory/

RewriteRule ^(.*)$ /subdirectory/$1

Open in new window


Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
PHP clean up nicely even if user abort 13 49
Trying to connect the LDAP over SSL 38 198
PHP Error Settings 12 76
Problem with .htaccess file 4 57
If your site has a few sections that need to be secure when data is transmitted between the server and local computer, such as a /order/ section for ordering or /customer/ which contains customer data, etc it would of course be recommended to secure…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now