如何使用.htaccess规则将.php重写为.html?

时间:2010-05-20 23:18:13

标签: .htaccess mod-rewrite

我想使用.php规则将.html扩展名转换为.htaccess扩展名

这是我可以做的事情吗?如果是的话,怎么做?

2 个答案:

答案 0 :(得分:11)

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]

使用mod_rewrite。 $ 1表示正则表达式的第一部分,[nc]表示不区分大小写。

您可以查看一下这篇文章:http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html

编辑: 删除了一行。我认为你不需要。 另外,评论我做了什么。

答案 1 :(得分:3)

也许试试

RewriteCond %{REQUEST_FILENAME} =-f
RewriteRule ^(.*)\.php$ $1.html [NC,L]

RewriteRule ^(.*)\.html$  $1.php [NC,L]
相关问题