1

How can I Replace .php with .html ?

I have all files with .php extension in my files directory

/files
  foo.php
  bar.php

I want browser to show them as

  http://example.com/files/foo.html
  http://example.com/files/bar.html 

Is this possible by .htaccss?

patricia perez
  • 511
  • 1
  • 4
  • 7
  • Really, you should search or try something before asking a question. There are so many results for this exact question, e.g. http://stackoverflow.com/questions/4548860/replacing-php-ext-with-html-through-htaccess – Frank Apr 15 '15 at 07:59

3 Answers3

3

Add this to your files/.htaccess

 RewriteEngine on 
 RewriteBase /files/ 
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)\.html$ /files/$1.php [NC,L]

this rewriteRule will redirect all .html requests to .php meaning that if you enter www.example.com/files/foo.htmlthen it will be internally redirected to www.example.com/files/foo.php and your browser will remain at www.example.com/files/foo.html

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
1

You need to use URL Rewrite on your .htaccess file, there is a post with the same question and is solved already here :

Rewrite

Community
  • 1
  • 1
Turrican
  • 607
  • 4
  • 9
1

Try this

RewriteEngine on  
RewriteBase /

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

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