如何在Apache2中使用mod_rewrite?

时间:2012-10-02 23:09:01

标签: mod-rewrite ubuntu apache2

我正在尝试使用带有mod_rewrite的Apache2进行简单的重定向。我在我的Apache中安装了模块,我在localhost / file1 / file2 / page.html中设置了一个网页。我在我的000默认文件中写这个:

RewriteEngine On
RewriteRule elegantdirectory/page.html file1/file2/page.html [L,NC]

所以现在如果我尝试访问localhost / elegantdirectory / page.html,服务器应该向我显示我在file1 / file2中的page.html。任何想法为什么不工作?

1 个答案:

答案 0 :(得分:0)

尝试在RewriteRule中包含边界和前导斜杠:

RewriteRule ^/elegantdirectory/page.html$ /file1/file2/page.html [L,NC]