Apache重写规则不起作用

时间:2014-01-14 11:45:39

标签: apache mod-rewrite url-rewriting

基本的重写规则不起作用,我不明白为什么。这是我的 hanalulu.conf

<VirtualHost *:80>

ServerName hanalulu.localhost
DocumentRoot /var/www/hanalulu/public
DirectoryIndex index.php

<Directory />
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>

RewriteEngine on
RewriteRule ^a.html$ b.html

</VirtualHost>

我在hosts文件中添加了一行并通过sudo a2ensite启用了该网站。重新启动的网络服务器:hanalulu.localhost/a.html请求a.html而不是b.html

有什么问题?

1 个答案:

答案 0 :(得分:5)

我认为你需要路径中的斜杠和RewriteRule上的标志,试试这个:

<VirtualHost *:80>

ServerName hanalulu.localhost
DocumentRoot /var/www/hanalulu/public
DirectoryIndex index.php

<Directory />
    AllowOverride all
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Directory>

RewriteEngine on
RewriteRule ^/a.html$ /b.html [R,L]

</VirtualHost>