用.html替换.php ext通过.htaccess

时间:2010-12-28 19:33:03

标签: php .htaccess

问候!

我正在尝试用.html

替换.php扩展名

到目前为止,我得到了:

RewriteRule ^(.*)\.html $1.php

...当输入/site/page.html等网址时效果很好(page.html实际上不存在但page.php确实存在。)

但我想要的是,在输入/site/page.php时,观看者只能在浏览器位置看到/site/page.html

这是可行的还是我必须为每个页面设置显式重定向? : - (

提前致谢。

ps:我正在使用的开发环境是os x上的XAMPP,如果它有任何区别

4 个答案:

答案 0 :(得分:17)

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

将白兔从帽子中拉出后进行编辑

RewriteEngine on  
RewriteBase /

RewriteCond %{THE_REQUEST} (.*)\.php  
RewriteRule ^(.*)\.php $1.html [R=301,L]  

RewriteCond %{THE_REQUEST} (.*)\.html  
RewriteRule ^(.*)\.html $1.php [L]  

答案 1 :(得分:0)

RewriteEngine on  
RewriteBase /

RewriteCond %{THE_REQUEST} (.*)\.php  
RewriteRule ^(.*)\.php $1.html [R=301,L]  

RewriteCond %{THE_REQUEST} (.*)\.html  
RewriteRule ^(.*)\.html $1.php [L]

答案 2 :(得分:-1)

尝试一下:

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L] 

答案 3 :(得分:-2)

我认为这很简单

AddType application/x-httpd-php .html

它只是正常处理每个.html文件.php

如果您只想要当前目录

<Files *.html>
ForceType application/x-httpd-php
</Files>