0

これらの行を.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>
4

1 に答える 1

0

VirtualHostセクションでは、パターンがホスト名とポートの後、クエリ文字列 (私の場合は "/") の前の URL の部分と一致することを理解しました。

ディレクトリ セクションでは、パターンはファイル システム パスに対して一致します。

于 2013-02-04T07:47:09.683 に答える