如何将我的.htaccess放入我的虚拟主机?

时间:2014-02-22 21:44:47

标签: apache

我想知道是否可以将.htaccess指令直接放在我的虚拟主机中。

我的.htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

我尝试使用我的虚拟主机(本主题故意删除了一些说明):

<VirtualHost *:80>

    ServerName domain.dev
    ServerAlias www.domain.dev

    <Directory /www/htdocs/domain/html/>

            Options -Indexes FollowSymLinks MultiViews
            AllowOverride All

    </Directory>

    <IfModule mod_rewrite.c>
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} -s [OR]
            RewriteCond %{REQUEST_FILENAME} -l [OR]
            RewriteCond %{REQUEST_FILENAME} -d
            RewriteRule ^.*$ - [NC,L]
            RewriteRule ^.*$ index.php [NC,L]
    </IfModule>

</VirtualHost>

但我的浏览器回复:

Bad Request
Your browser sent a request that this server could not understand.

1 个答案:

答案 0 :(得分:0)

它适用于:

<Directory /www/htdocs/domain/html/>

    Options -Indexes FollowSymLinks
    AllowOverride All

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]

</Directory>