Link to home
Start Free TrialLog in
Avatar of nosolb
nosolbFlag for United States of America

asked on

Setting up subdomains with .htaccess

I would like to setup a subdomain so that when a user types http://news.example.com the content displayed in the browser comes from the directory example.com/news. I have updated the .htaccess file and it performs a redirect. I would like to know if it would be possible to maintain the subdomain present in the URL (https://news.example.com) instead of the redirect (http://www.example.com/news)

Please see code below
# redirect subdomain to the specific folder
# host does not start with www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
RewriteRule ^(.*) http://example.com/%1/$1 [R=301,L]

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of noci
noci

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
SOLUTION
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 noci
noci

any further questions?
Avatar of nosolb

ASKER

Hello,

Thank you to both of you for your help. Unfortunately, your recommendations are not quite what I was looking for. The examples do perform a redirect but I am interested in a silent/transparent redirect, so the user does not know that he/she is being redirected. So when the user types http://news.example.com, the content should be obtained from the directory /news (http://example.com/news) but the URL bar in the browser shall display http://news.example.com after the redirect.

I have read that I might have to update the vhosts file and maybe DNS (wildcard A)...do you have any recommendations?

Thanks again.
Avatar of nosolb

ASKER

The answer was helpful but did not fully resolve my problem. Thank you.