Mod rewrite PHP to HTML using htaccess

how you can rewrite all your PHP pages to HTML using a simple .htaccess rule for better search engine indexing. This is a basic category.php to category.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.

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.

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.

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, product.php, services.php, category.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.

Visitors can now access the contents of products.php using products.html

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 14x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply