Latest tutorial: Making a Movieclip face another Movieclip or point on the stage | Ask Tutorial5!
 

Mod rewrite PHP to HTML htaccess

(24 votes)
Software - Scripting
Written by DanielRo   
In this tutorial you are going to learn how you can rewrite all your PHP pages to HTML using a simple .htaccess rule for better search engine indexing. This is a basic page.php to page.html htaccess script.
In this tutorial we are providing a script that can only work if you are hosted on a Linux server.

There is a myth saying that search engines will better index your site if your pages are displayed like static HTML.

Personally I don't believe it actually makes a difference for search engines if your pages are either PHP or HTML but in the long run it can increase your sites security.

The language your site is coded in is irrelevant and also a security vulnerability, if people know what language your site is coded in, they'll more easily be able to exploit any code vulnerabilities.

Say for example you have a website and a menu witch 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]


One would also have to change all the links trough 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.


Subscribe now via RSS feed and get all the new tutorials

written by rahul111 , November 13, 2008

http://localhost/project/index...egory_id=5

rewrite url : http://localhost/project/index.php/category
i use xampp server
how can do...
written by jeo , November 26, 2008

thnx
Jeo
http://casiowatches.biz
written by occasional Idea , November 26, 2008

How to change dynamic path to .htm or .html path
e.g.
http://www.domain.com/category.php?cat=1 where cat=1 is "system"
convert to
http://www.domain.com/system.htm

written by Paul Hutchinson , December 12, 2008

how can i do somthing like this for images?
RewriteRule ^(.*).png$ images/$1.png [L]
but theres a problem.
when trying to view a image it sets of a never ending loop.

How can i solve this

Thankyou
Paul
written by Hitesh Patil , January 05, 2009

I used it. It works but when there is really .htm file and when i access it then it give [file name].php is missing. i mean 404 error.
I want that if .htm file is present then it should not seek .php
written by Brandon , January 08, 2009

I did this on my index, which I didn't really know what this did. Now it's asking me to download my index page of my website. How can I take this off, because deleting the .htaccess file didn't turn it off.

I hope you reply, because I am so lost here.
written by tran thai , April 30, 2009

thank you for useful informations about mod rewrite.
written by Amit Sidhpura , July 24, 2009

Thanks man, after half an hour of search this is the page where i found the required solution. Thanks again..Keep it up..
written by AndrewAM , September 29, 2009

I notice none of the questions have been answered?
I have been trying for a few weeks to rewrite php file extensions to html and have been failing, I've used exactly the same code posted in so many forums but no success? Any ideas?
Andrew
written by Natalya Shirinova , February 02, 2010

how to change from

http://www.example.com/?cat=1

to

http://www.example.com/Category/

plz help, thanks
written by Mayur Shah , February 03, 2010

hi

Options FollowSymlinks
RewriteBase /
RewriteRule ^(.*).html $1.php

This is useful when you need to convert from PHP to html extensions same time if you need to pass more parameter with different php file than need to write something like this

Options FollowSymlinks
RewriteBase /
RewriteRule (.*).htm$ /page.php?file=$1

We had done with this like you can see both options is working fine
http://www.addonsolutions.com hire php developer . html

There are more options too

Thanks


Do you need more help? Ask now!
 

busy
Last Updated ( Tuesday, 29 July 2008 )