Reputation: 223
Im having some issues with the virtual hosts apache files and htaccess. I have apache, updated to 2.6 yesterday. I installed 2 virtual domains on it, and disabled the default domain. All works fine, sites loads fine, no problems there.
The first virtual domain has a htaccess with +50 rewrite conditions and all them work fine! I tried to add some conditions to the 2nd domain, but the ones that rewrite directories dont work.
This is the condition:
RewriteRule ^user/([a-zA-Z0-9_-]+)$ index.php?username=$1
RewriteRule ^user/([a-zA-Z0-9_-]+)/$ index.php?username=$1
And there, the "sites-available" apache config files for each domain (only the relevant things):
DOMAIN 1:
ServerAdmin webmaster@localhost
ServerName domain1.com
ServerAlias www.domain1.com
DocumentRoot /var/www/domain1.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
<Directory /var/www/domain1.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
DOMAIN2:
ServerAdmin webmaster@localhost
ServerName domain2.com
ServerAlias www.domain2.com
DocumentRoot /var/www/domain2.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
<Directory /var/www/domain2.com/public_html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
As you can see, there is no diference between them other than the path to main folder. I dont understand whats wrong with it. Why the first domain works perfect and the second one no.
Some things:
A: Any other condition on the domain2 htaccess file works just fine, like redirec simply html to php, or errorhandlers, or just simply redirects to test.
B: I pasted the same rewrite condition in my first domain htaccess file, and it works perfect!
It looks like the apache config file is not working correctly.
Is there anything I must check/change?
I will appreciate any help, and sorry for my english.
Upvotes: 0
Views: 511
Reputation: 19528
Give this a try its tested and working:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^user/([a-z0-9_-]+)/?$ /index.php?username=$1 [NC,L]
I believe the issue is that you have MultiViews
enabled, you can also resume your 2 rules into 1 like I have done above.
This should go into the .htaccess
of your domain2.
As a side note, you do not need 2 directories directives, you can remove this one:
<Directory />
Options FollowSymLinks
AllowOverride ALL
</Directory>
And keep just:
<Directory "/var/www/domain2.com/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride ALL
Order allow,deny
allow from all
</Directory>
Upvotes: 1