问候!
我正在尝试用.html
替换.php扩展名到目前为止,我得到了:
RewriteRule ^(.*)\.html $1.php
...当输入/site/page.html
等网址时效果很好(page.html
实际上不存在但page.php
确实存在。)
但我想要的是,在输入/site/page.php
时,观看者只能在浏览器位置看到/site/page.html
。
这是可行的还是我必须为每个页面设置显式重定向? : - (
提前致谢。
ps:我正在使用的开发环境是os x上的XAMPP,如果它有任何区别
答案 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>