How to use PHP in pages with a .html extension (or any other)
5 Comments Published by Steven 4 years, 4 months ago in Basics and PHPTo be able to use php code on a page with an extension other than .php, you need a server which supports .htaccess files.
To add an extension to be parsed for php, create or edit a file called .htaccess (with the dot first) containing the following line:
AddType application/x-httpd-php .html .moo .htm
This tells the server to check for php code and execute it in files with extensions .html, .moo or .htm. So upload that .htaccess file in the same folder as your .html files with PHP code inside them (using PHP tags: <?php ... ?>) then when you view them in the browser, the PHP should be dealt with as you’d expect from a PHP page.
5 Responses to “How to use PHP in pages with a .html extension (or any other)”
Leave a Reply
You must log in to post a comment.
Search
Categories
- ASP (3)
- ASP Basics (3)
- Blogs (2)
- C# (1)
- Firefox (1)
- Flash (1)
- Google (6)
- Hacks (3)
- Java (1)
- PHP (12)
- Basics (8)
- Files (1)
- Image Handling (3)
- Ruby (1)
- Tips (10)
- Web Hosting (3)
- Web Hosting Articles (1)
- Web Hosting News (2)
- Windows (6)
- Wordpress (2)
Related Entries
- No related posts.
Why would you want to do this?
great! & greatest infromation. thanks.
I have good page ranking however I wanted to use php on the pages without resorting to making it a page with php extension. It really works…is there a downside though?
You can do something similar with mod rewriting, though it is more complicated. The whole idea behind making php “appear” like static html is, generally, for search engine optimization reasons. Many search engines do not like dynamically generated content, leading some webmasters to “trick” search engines by making them think that dynamic php pages are really static html.
I think a more important reason is so that if you ever switch to a different server-side scripting language, you don’t have to break all existing links.