Replacing .php ext with .html via .htaccess

Hello!

I am trying to replace .php extensions with .html

So far I have received:

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

... it works well when url is entered as /site/page.html (and page.html does not physically exist, but page.php ).

However, what I would like to have is when /site/page.php is entered, the viewer only sees /site/page.html in the browser location.

Is this doable or do I need to set up explicit redirects for each page ?: - (

Thanks in advance.

ps: dev environment I use XAMPP on os x if that matters

+7
source share
4 answers
 RewriteRule ^(.*)\.php $1.html [R=301,L] RewriteRule ^(.*)\.html $1.php 

edit after pulling the white rabbit out of the hat

 RewriteEngine on RewriteBase / RewriteCond %{THE_REQUEST} (.*)\.php RewriteRule ^(.*)\.php $1.html [R=301,L] RewriteCond %{THE_REQUEST} (.*)\.html RewriteRule ^(.*)\.html $1.php [L] 
+14
source
 RewriteEngine on RewriteBase / RewriteCond %{THE_REQUEST} (.*)\.php RewriteRule ^(.*)\.php $1.html [R=301,L] RewriteCond %{THE_REQUEST} (.*)\.html RewriteRule ^(.*)\.html $1.php [L] 
0
source

Try:

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

I think it is very simple.

 AddType application/x-httpd-php .html 

it processes each .html file as a regular .php

if you want it only for the current directory

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

All Articles