これらの行を.htaccessすべてに配置すると、すべてがうまく機能します(に行くと、http://www.example.ruにリダイレクトされhttp://example.ruます)。
RewriteEngine On
# Installation directory
RewriteBase /
# Redirect all www to non-www
RewriteCond %{HTTP_HOST} ^www.example.ru [NC]
RewriteRule ^(.*)$ http://example.ru/$1 [L,R]
しかし、まったく同じ行を<VirtualHost>-><Directory>セクションに配置すると、 に移動しようとすると にhttp://www.example.ruリダイレクトされhttp://example.ru/wwwます。
理由を知っている人はいますか?
UPD
新しいVirtualHost:
<VirtualHost *:80>
ServerName example.ru
ServerAlias www.example.ru
ServerAdmin webmaster@localhost
DocumentRoot /home/example/www/example.ru/www
RewriteEngine On
<Directory /home/example/www/example.ru>
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/example/www/example.ru/log/error.log
LogLevel warn
SetEnvIf Remote_Addr 127.0.0.1 loopback
CustomLog /home/example/www/example.ru/log/access.log combined env=!loopback
# Redirect all www to non-www
RewriteCond %{HTTP_HOST} ^www.example.ru [NC]
RewriteRule ^(.*)$ http://example.ru$1 [L,R]
</VirtualHost>