1
votes

I decided to add virtual hosts on apache. My previous conf was:

<VirtualHost *:80> ServerName domain1.com DocumentRoot /var/www/ </VirtualHost>

I have .htaccess in /var/www/ which was doing redirect for non-www to www and subdomain like forum.domain1.com to www.domain1.com/forum This is my htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^forum\.domain1\.com$
RewriteRule ^ http://www.domain1.com/forum%{REQUEST_URI} [P]
RewriteCond %{HTTP_HOST} !^www..*
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]*).(com|com/)
RewriteRule ^.*$ http://www.%1.%2{REQUEST_URI} [R=301,L]

Now i have two domains and i setup virtual hosts using this tutorial: Virtual host on ubuntu

So, now in my /etc/apache2/sites-available i have 3 files, default, domain1.com and domain2.com. .htaccess stayed in /var/www/ and its working for domain1.com but it is not working for domain2.com. Do i need to change .htaccess in /var/www/ to accept domain2 or i can add .htaccess to /var/www/domain2.com/public_html/ ? Do i need to move previous .htaccess from /var/www/ to /var/www/domain1.com/public_html? Thanks in advance!

1

1 Answers

1
votes

Why do you have .htaccess in your www folder, you should put them in the vhost DocumentRoot and use each .htaccess to control each site individually.

so your tree should be:

/var/www/
 - domain1.com
   - .htaccess
 - domain.com
   - .htaccess

siteroot .htaccess files should only be used in exceptional circumstances, otherwise there is no point in using Vhosts... might aswell just have 1 vhost and let .htaccess do the rest.