【问题标题】:How to use mod_rewrite in Apache2?如何在 Apache2 中使用 mod_rewrite?
【发布时间】:2012-09-23 20:44:16
【问题描述】:

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

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

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

【问题讨论】:

    标签: mod-rewrite ubuntu apache2


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-21
      • 2011-09-15
      • 2018-02-03
      • 1970-01-01
      • 1970-01-01
      • 2013-11-09
      • 1970-01-01
      • 2012-07-16
      相关资源
      最近更新 更多