6

I want to convert .php extension to .html extension using .htaccess rules

Is this something I can do, and if so, how?

2
  • I cleaned up your question a bit to make it more clear, I hope you don't mind. Commented May 20, 2010 at 23:24
  • The logical way would be the other way round: requests of foo.html would be rewritten to foo.php. Commented May 21, 2010 at 11:31

2 Answers 2

12
RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]

Uses mod_rewrite. $1 indicates first part of the regex and [nc] means not case sensitive.

You can take a look at this article: http://roshanbh.com.np/2008/02/hide-php-url-rewriting-htaccess.html

EDIT: Removed a line. You do not need that I think. Also, commented on what I did.

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

6 Comments

it doesn't seems to work.. i have a directory of tradesalvage/demo under localhost .. wat should i put?
I think you do not need that first line so I edited that. Make sure that mod_rewrite in your Apache http.conf is loaded and not commented out. I tried it on my machine. It works. Here is what I did: 1.) added those two lines in my .htaccess file. Saved in the htdocs/webroot. Created a index.php file. and went to browser and accessed it as index.html. Let me know.
I did this exact thing yesterday and it worked. The only problem is mod_rewrite was not enabled before. Google for "verify mod_rewrite is working" if in doubt
ooh sorry, my initial thought was wrong. I thought i can access throuhg index.php and the URL will display index.html. If this is the case, i might want to just display index without any extension. I tried with the following but still nothing happen, the URL display as usual as index.php RewriteEngine on RewriteRule ^(.*)\$ $1.php [nc]
|
3

Maybe try

RewriteCond %{REQUEST_FILENAME} =-f
RewriteRule ^(.*)\.php$ $1.html [NC,L]

RewriteRule ^(.*)\.html$  $1.php [NC,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.