Apache简单重写规则在httpd-vhosts.conf中运行良好,但在.htaccess文件

时间:2017-01-10 11:30:55

标签: apache .htaccess mod-rewrite url-rewriting

Apache 2.4,Windows 10

httpd-vhosts.conf中的虚拟主机:

<VirtualHost sporemvc:80>
    ServerAdmin jakub.sawczuk@gmail.com
    DocumentRoot "C:/Apache24vhosts/hosts/sporemvc"
    ServerName sporemvc
    ErrorLog "logs/sporemvc-error.log"
    CustomLog "logs/sporemvc-access.log" common
    <Directory C:/Apache24vhosts/hosts/sporemvc>
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ /index.php [L]
    </Directory>
</VirtualHost>

这很好用。并且证明mod_rewrite已经开启。

当整个目录不存在时:

<VirtualHost sporemvc:80>
    ServerAdmin jakub.sawczuk@gmail.com
    DocumentRoot "C:/Apache24vhosts/hosts/sporemvc"
    ServerName sporemvc
    ErrorLog "logs/sporemvc-error.log"
    CustomLog "logs/sporemvc-access.log" common
</VirtualHost>

并且有C:/Apache24vhosts/hosts/sporemvc/.htaccess文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]

重写规则似乎根本不起作用--Apache说404.可能有什么问题?我确保mod_rewrite打开,甚至.htaccess是ANSI而不是UTF。在Apache和vhost的日志中,只有404个。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

是的,我很笨。

AllowOverride无法更改为AllowOverride All(嗯,All可以进行开发)。

Causa finita。