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

问题描述 投票:7回答:4

问候!

我正在尝试用.html替换.php扩展名

到目前为止我得到了:

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

...当/site/page.html这样的网址被输入时它很好用(并且page.html实际上不存在,但page.php确实存在)。

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

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

提前致谢。

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

php .htaccess
4个回答
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]  

0
投票
RewriteEngine on  
RewriteBase /

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

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

-1
投票

尝试一下:

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

-2
投票

我认为这很简单

AddType application/x-httpd-php .html

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

如果你只想要当前的目录

<Files *.html>
ForceType application/x-httpd-php
</Files>
© www.soinside.com 2019 - 2024. All rights reserved.