My domain domain.com is redirected to www.domain.com but, due to internal redirects, it only works in some cases:
- domain.com/folder/ should redirect to www.domain.com/folder/ but it is redirected to www.domain.com/blog/index.php
The issue here is that internally, www.domain.com/folder/ uses that blog/index.php throught a RewriteRule:
RewriteRule ^$          ../blog/index.php
I don't know why, but you are redirected to the script instead of the nice URL.
IT WORKS here (redirection from domain.com/folder/ to www.domain.com/folder, when all code within same "Directory" entry):
<Directory /var/www/vhosts/domain.com/httpdocs/>
    Options -All +FollowSymLinks
    RewriteEngine on
    # redirect non-www to www
    RewriteCond %{HTTP_HOST}        ^domain\.com
    RewriteRule ^(.*)$          http://www.domain.com/$1 [R=301,L] 
    RewriteRule ^folder/$           ../blog/index.php                       
</Directory>
It does NOT WORK here (redirection from domain.com/folder/ to www.domain.com/blog/index.php, when 2 "Directory" entries are used):
<Directory /var/www/vhosts/domain.com/httpdocs/>
    Options -All +FollowSymLinks
    RewriteEngine on
    # redirect non-www to www
    RewriteCond %{HTTP_HOST}        ^domain\.com
    RewriteRule ^(.*)$          http://www.domain.com/$1 [R=301,L]                      
</Directory>
<Directory /var/www/vhosts/sonidon.com/httpdocs/folder/>
    RewriteEngine on
    RewriteRule ^$          ../blog/index.php
</Directory>
Tested also using Options +FollowSymLinks +SymLinksIfOwnerMatch in both directories with no luck :(
I saw a solution here using VirtualHosts instead of Directory: Generic htaccess redirect www to non-www but think that it should be a way to do this because this trouble is not only related to "non-www to www" but to any redirection.
 
     
    