views:

30

answers:

1
+1  Q: 

php and htaccess

In the .htaccess file can we change the file extention to be display. Like my .htacces file rewrite any .html files to .php fileS WITH THE BELOW CODE.

RewriteEngine On 
RewriteRule (.*).html$ $1.php [L]

If the URL typed as http://localhost/test/test.html it will internally called test.php file. However I would like the page to have the.php extension on it as well right now it stays with the .html extension. Is this possible?

+2  A: 

You can do that like this:

RewriteEngine On 
RewriteRule (.*).html$ $1.php [R-302,L]

However I would advise against doing this. The first version you have is an internal redirect. It incurs no round trip to the client. This version does. When the Web server receives a request for index.html it sends a redirect back to the client to index.php. It then receives another request for index.php.

This is an unnecessary round trip and can only make your site slower.

It isn't possible to change what's in the address bar this way without the external redirect.

cletus