您好!
我正在尝试用 .html 替换 .php 扩展名
到目前为止我得到:
RewriteRule ^(.*)\.html $1.php
... 当输入像 /site/page.html
这样的 url 时,它工作得很好(并且 page.html
实际上并不存在,但是 page.php
确实如此)。
但是我想要的是,当输入 /site/page.php
时,查看者只能在浏览器位置看到 /site/page.html
。
这是可行的还是我必须为每个页面设置显式重定向? :-(
提前致谢。
ps: 我使用的开发环境是 os x 上的 XAMPP,如果它有任何区别的话
最佳答案
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]
关于php - 通过 .htaccess 将 .php ext 替换为 .html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4548860/