Rewrite PHP extension to HTML using htaccess

Programming for Search Engines 101. An area for avid PHP and .NET developers to chat about Programming techniques and how to make better use of search engines.

Moderator: Moderators

Rewrite PHP extension to HTML using htaccess

Postby silvester » Tue Oct 27, 2009 5:57 am

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.
silvester
 
Posts: 89
Joined: Mon Nov 10, 2008 12:59 am

Re: Rewrite PHP extension to HTML using htaccess

Postby Mike » Tue Oct 27, 2009 2:02 pm

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
Mike
 

Re: Rewrite PHP extension to HTML using htaccess

Postby latha » Tue Oct 27, 2009 9:47 pm

latha
 


Return to Programming

Who is online

Users browsing this forum: No registered users and 6 guests

cron