How to run PHP code in HTM/HTML files

Home Forums Coding & Scripts How to run PHP code in HTM/HTML files

This topic contains 0 replies, has 1 voice, and was last updated by  CatWiki 9 months, 3 weeks ago.

Viewing 1 post (of 1 total)
  • Author
  • #180


    PHP code offers websmasters the ability to offer/include dynamic content in web pages, like date/time, content from other files or external sources. While you can do that with javascript as well, content from scripts are not visible to search engines, hence it creates zero value from a SEO point of view.

    If you have a website that is based on HTM/HTML files, then you know that including PHP code in these files does nothing. And changing your web pages to .php is also no recommended for an established website – losing any SEO value up to the point of the change.

    Luckily running PHP code in HTM/HTML files can be done with a simple command that tells the server to also run php code in .htm/.html files. You need to include the following command line in your .htaccess file available in the root folder of your website

    AddType application/x-httpd-php .html .htm

    How to do that?
    1. go to the root folder of your website with a FTP program or WebFTP from your hosting account
    2. find the .htaccess file and download it on your PC
    3. open the .htaccess file with Notepad
    4. copy the above line of code and paste it on a new line in the .htaccess file
    5. save the file and upload it back to your server, overwriting the older file

    Go to you website and check the htm/html page where you included the php code to see if it works.

    PS: if you do not have a .htaccess file in the root folder of your file do this:
    1. create a htaccess.txt file with your notepad
    2. copy and paste the above line of code in the file
    3. save the file and upload it to your server where your website is
    4. rename on the server the file from “htaccess.txt” to “.htaccess”

    Note 1: Please note that the website should be hosted on a linux/apache server (which is more than likely; shared hosting accounts are more than likely to be linux/apache).

    Note 2: The above code might not work on all shared hosting because of their own in-house settings. But if this doesn’t work, check your hosting provider’s FAQ/Help section as it will surely show you the code that needs implemented in the .htaccess file. If you don’t find it, just contact them and you will surely get the correct code to use.

    Alternative codes to be used/tested:

    AddType application/x-httpd-php5 .html .htm – if your PHP version is 5

    AddHandler x-mapp-php5 .html .htm – for 1and1 hosting

    • This topic was modified 9 months, 3 weeks ago by  CatWiki.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.