通过 .htaccess 用 .html 替换 .php ext [英] replacing .php ext with .html through .htaccess
问题描述
您好!
我正在尝试用 .html 替换 .php 扩展名
I'm trying to replace .php extensions with .html
到目前为止我得到了:
RewriteRule ^(.*).html $1.php
...当输入像 /site/page.html
这样的 url 时它工作得很好(并且 page.html
实际上不存在但 page.php
确实如此).
... it works nicely when url like /site/page.html
is entered (and page.html
does not physically exist but page.php
does).
但是我想要的是,当输入 /site/page.php
时,查看器在浏览器位置只能看到 /site/page.html
.
However what I'd like to have is when /site/page.php
is entered the viewer sees only /site/page.html
in the browser location.
这是可行的还是我必须为每个页面设置显式重定向?:-(
Is that doable or do I have to set up explicit redirects for each page? :-(
提前致谢.
ps:我使用的开发环境是 os x 上的 XAMPP,如果它有任何不同的话
ps: dev environment I'm using is XAMPP on os x if it makes any difference
推荐答案
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]
这篇关于通过 .htaccess 用 .html 替换 .php ext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!