views:

59

answers:

2

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

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

+1  A: 
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.

AJ
it doesn't seems to work.. i have a directory of tradesalvage/demo under localhost .. wat should i put?
redcoder
example i have http://localhost/tradesalvage/demo
redcoder
i tried the code above but still have the .php ext
redcoder
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.
AJ
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
satyajit
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.phpRewriteEngine onRewriteRule ^(.*)\$ $1.php [nc]
redcoder
I think this article might help you: http://eisabainyo.net/weblog/2007/08/19/removing-file-extension-via-htaccess/or this:http://www.blog.highub.com/apache/http-server/remove-file-extension-using-htaccess/
AJ
+1  A: 

Maybe try

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

RewriteRule ^(.*)\.html$  $1.php [NC,L]
Don