Issue
I've set up my own server.
Let's say my main server folder is /home/www
and I've set the nameservers so that all domains point to this location.
Now, here's what I want to do :
- Have each domain's files in a separate subfolder
- Based on the domain requested, silently redirect to the appropriate subfolder
E.g.
- if we need
somedomain.com
orwww.somedomain.com
orwww.somedomain.com/anything/
(or any such variation for that matter) redirect the request from/home/www/
to/home/www/somedomain.com/
How can this be done?
And here's what I've tried (but given that .htaccess
is definitely ... not my thing, it'll most likely be close to non-sensical...) :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www.)?somedomain.com$ [NC]
RewriteRule ^(/)?$ somedomain.com [L]
Solution
There are two possible choices. you can create Virtual Host for each domain and set virtual document root. Or You can use rewrite rule.
From apache Virtual host documentation:
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /www/www.example1.com
ServerName www.example1.com
# Other directives here
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /www/www.example2.org
ServerName www.example2.org
# Other directives here
</VirtualHost>
You can find out more in http://httpd.apache.org/docs/2.2/vhosts/examples.html
Answered By - ZubaiR