Organizational Research By

Surprising Reserch Topic

how ro write apache map single subdomain to folder



asked Sep 22, 2013 in APACHE by rajesh
0 votes
50 views



Related Hot Questions

2 Answers

0 votes
In my /var/www I have a number of sites (goodsite, badsite, uglysite). Right now they are accessed by mydomain.com/goodsite, etc..
 
What I want is for one site in particuar, uglysite, to be accessed by uglysite.mydomain.com - the others remain as they are.
 
I have tried all sorts of ways of fiddling with the.htaccess (in /var/www). Note I have mod-rewrite enabled and mod vhost-alias enabled.
 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^uglysite\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/uglysite/
RewriteRule ^(.*)$ /uglysite/$1 [L]
What ends up happening is that both mydomain.com and uglysite.mydomain.com always map to the same thing (i.e., the index at /var/www). I tried adding in a new virtual host, and was surprised to find that uglysite.mydomain.com mapped correctly, but then mydomain.com also mapped directly to uglysite as well.
 
       ServerName uglysite.mydomain.com
       ServerAdmin www@localhost
       DocumentRoot "/var/www/"
       AccessFileName .htaccess
       
               Order allow,deny
               Allow from All
               AllowOverride All
       
The above was added to my sites-enabled/000-default file. This got uglysite.mydomain.com to work properly, but then mydomain.com mapped to the same thing!
answered Sep 22, 2013 by rajesh
0 votes
You should be making uglysite into a second file instead of modifying 000-default
 
So, take a copy of the 000-default file, change the subdomain as you have done up there and modify the directory to /path/to/site
 
000-default:
 
       ServerName mydomain.com
       ServerAdmin www@localhost
       ServerAlias mydomain.com
       DocumentRoot "/var/www/goodsite"
       AccessFileName .htaccess
       
               Order allow,deny
               Allow from All
               AllowOverride All
       
uglysite:
 
       ServerName uglysite.mydomain.com
       ServerAlias uglysite.mydomain.com
       ServerAdmin www@localhost
       DocumentRoot "/var/www/uglysite"
       AccessFileName .htaccess
       
               Order allow,deny
               Allow from All
               AllowOverride All
       
Also note that in the above samples, I have modified the DocumentRoot to point to the directory that you want file served from
 
EDIT: virtualhosts set to *:80 since your sites point to your own ip anyway
answered Sep 22, 2013 by rajesh

...