Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Make HTML Files Run PHP Code

This guide shows you how to let files that end in .html run PHP code, so you do not need to rename them to .php.

How-To Guides2 min read14 steps

Why is this needed?

HTML is the plain language of web pages. PHP is a programming language that makes pages smart, for example by showing today's date. The server treats the two differently. It only runs PHP in files that end in .php.

If you put PHP code inside a .html file, the server just shows it as text. A setting in the .htaccess file can change that. A .htaccess file is a small settings file for the Apache web server.

Warning: A wrong line in .htaccess can cause a 500 error and take your site down. Download a copy of the file before you edit.

Steps

  1. Log in to your hosting control panel.
  2. Open File Manager.
  3. Click Settings and tick Show Hidden Files (dotfiles).
  4. Go to the folder of your website, usually public_html.
  5. Find .htaccess. If it is not there, click + File and create it.
  6. Download a copy as a backup.
  7. Right-click it and choose Edit.
  8. Add one of the following blocks at the end. Which one works depends on how PHP is set up on your plan.
    AddType application/x-httpd-php .html .htm
    This tells Apache to treat HTML files as PHP. On some servers you need a version-specific line, like:
    AddHandler application/x-httpd-php81 .html .htm
    Hostvento support can tell you the right handler name for your plan. If you use cPanel's MultiPHP Manager, a handler line may be added there for you.
  9. Click Save Changes.

Test it

  1. Create a file named test.html in public_html.
  2. Put this inside it:
    <?php echo "PHP works"; ?>
  3. Open https://yourdomain.com/test.html.
  4. If you see the words "PHP works", it is on. If you see the code, it is not.
  5. Delete the test file afterwards.

Things to know

  • Every .html file is now sent through PHP. This can slow a very big site slightly.
  • If the browser downloads the file instead of showing it, remove the line and ask support for the correct handler.

Quick recap

  • By default only .php files run PHP.
  • Add an AddType or AddHandler line in .htaccess.
  • Back up first.
  • Test with a small file.