How to use PHP in pages with a .html extension (or any other)
Published 2 years, 5 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.
If you have a low-traffic website, consider joining the Money4Banners advertising network. They will pay you £10 + £5 each month for displaying a small advert on three of your pages, regardless of traffic. American webmasters are welcome, and since £10 == $20, you make more!
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)
- deals (1)
- Firefox (1)
- Flash (1)
- Google (6)
- Hacks (4)
- Java (1)
- PHP (12)
- Basics (8)
- Files (1)
- Image Handling (3)
- Puzzles (1)
- Ruby (1)
- Tips (10)
- Web Hosting (3)
- Web Hosting Articles (1)
- Web Hosting News (2)
- Windows (6)
- Wordpress (2)
Related Entries
- PHP
- How to use the query string in PHP
- Save Embedded Media and Other Files in Firefox
- How to use the QueryString in ASP
- Find a visitor's IP Address with PHP
- Reading a file's contents with PHP
- Generate a Month Calendar In PHP
- Add Notepad To Your "Send To" Menu
- Rotating Images with PHP
- Yahoo! Webhosting Integrates Movable Type
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.