Page 1 of 1

Rewrite PHP extension to HTML using htaccess

PostPosted: Tue Oct 27, 2009 5:57 am
by silvester
If you have a website and a menu which is dynamically built using PHP, you could only use it on PHP pages.

Example:
You have menu.php and all the pages of your site: index.php, services.php, portofolio.php, contact.php

Using the following script you will be able to access the contents of all your pages using a HTML extension.


The .htaccess file starts here

RewriteEngine on
RewriteBase /
RewriteRule ^(.*)\.html$ $1.php [L]

Also You have to change all the links through out the website from the PHP extension to HTML.

Your visitors can now access the contents of services.php using services.html

Using this htaccess basic PHP to HTML rewrite rule you can present PHP files as HTML.

Re: Rewrite PHP extension to HTML using htaccess

PostPosted: Tue Oct 27, 2009 2:02 pm
by Mike
Nice rewrite rule. I'll put that one in the bank. :)

I've also used:

AddType application/x-httpd-php .html

...and just parsed html files with php. It tends to get a little heavy on the server so I use it sparingly.

Mike

Re: Rewrite PHP extension to HTML using htaccess

PostPosted: Tue Oct 27, 2009 9:47 pm
by latha