Friday, December 14, 2007

Use other extension for PHP scripts

To be able to use php scripts on a page with an extension other than default .php, you need a server which supports creating/editing .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 .foo .htm
This tells the server to check for php code and execute it in files with extensions .html, .foo 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.

Another way is by using mod rewrite (here is an excellent tutorial about mod rewrite)

No comments: