Apache重写规则不起作用

sit*_*lge 0 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>
Run Code Online (Sandbox Code Playgroud)

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

问题是什么?

arc*_*444 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>
Run Code Online (Sandbox Code Playgroud)