Can I put PHP code in .html or .htm files?


You can run PHP code in .html/.htm files by changing the .htaccess file.

To change the .htaccess file:

  1. Back up your .htaccess file
  2. Open your .htaccess file or create one in a text editor
  3. At the end of the file, paste this code:

AddHandler cgi-script .html
SetEnv PHP_EXTENSION .html
AddHandler cgi-script .htm
SetEnv PHP_EXTENSION .htm

  1. Upload the new .htaccess file to your server
  2. PHP code will now run in .htm and .html files


Article ID: 423
Created On: Mon, Mar 16, 2015 at 3:36 PM
Last Updated On: Thu, Apr 23, 2015 at 12:20 PM

Online URL: https://www.heartinternet.uk/support/article/can-i-put-php-code-in-html-or-htm-files.html