htaccess重定向所有文件类型

时间:2015-10-02 15:56:35

标签: php .htaccess mod-rewrite redirect

您好我很难理解.htaccess和mod_rewrite是如何工作的。

我希望将.html文件的所有请求重定向到php文件,该文件会呈现所请求的页面。如何执行此操作,因此所有页面请求(例如example.comexample.com/index.htmlexample.com/test.html都将被index.php重定向(内部处理)?

我试过这个

RewriteRule ^(.*)\.html$ $1.php [L,R=301]

但它没有改变一件事?

1 个答案:

答案 0 :(得分:1)

您需要删除R标记,否则浏览器将重定向到.php网址:

RewriteEngine On

RewriteRule ^(.+?)\.html$ $1.php [L,NC]