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 回答