nosolb
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
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]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
any further questions?
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.
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.
ASKER
The answer was helpful but did not fully resolve my problem. Thank you.