Problem With Vhost Conf Rewriting Rule + .htaccess Conf

Hello all.

The matter: I have plenty of websites to handle, and most of them are yii based. Since I had to fix a bad behaviour on the domain conf (letting the website being surfable from www.domain and domain, risking SEO duplication content error), I decided to redirect every www.domain occurrence in my server, redirecting to the corrispondent

My approach was to create a vhost.conf, made this way:

code in the next post... :|

This way I can rewrite my www.whatever (secure and not secure).

Once I check it on the server, I can see it is working without problems.

Then I deploy yii and here starts the pain.

This is my htaccess:

#Options +FollowSymLinks

#RewriteEngine on

# if a directory or a file exists, use it directly

#RewriteCond %{REQUEST_FILENAME} !-f

#RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php

#RewriteRule ^.*$ index.php [L]

If I have the .htaccess on the root there is no redirect at all, as if no vhost.conf is set.

If I remove the .htaccess the rewrites are ok but I can’t hide the front controller, index.php.

I guess that the problem is in the .htaccess, but I’m not a sys admin, so I’m pretty puzzled.

Thanks in advance if anybody can help me to find out what’s the problem with this configuration.

ps: I’d prefer to demand the www rewrite a level below than .htaccess, because I actually prepared a vhost.conf skeleton, which should let me create new projects worrying about this matter no more… once it will be fixed, of course :)

<Directory /var/www/vhosts/>

	RewriteEngine On

	RewriteCond %{HTTPS} off

	RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]

	RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

	RewriteCond %{HTTPS} on

	RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]

	RewriteRule ^(.*)$ https://%1/$1 [R=301,L]