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?

1
  • Really, you should search or try something before asking a question. There are so many results for this exact question, e.g. stackoverflow.com/questions/4548860/… Commented Apr 15, 2015 at 7:59

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

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] 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.