PHP/MariaDB/MySQL

How to Parse HTML as PHP

Updated November 2026 17,137 views 4 min read
PHP/MariaDB/MySQL | Updated November 2026

By default, Apache only processes files with a .php extension through the PHP interpreter. If you want .html or .htm files to be parsed as PHP (so they can contain PHP code), you need to add a handler directive to your .htaccess file. This is a common need when migrating from an older site that uses .html extensions but now needs PHP functionality.

01. The .htaccess Method

Add this line to your .htaccess file:

AddHandler application/x-httpd-lsphp .html .htm

This tells Apache to send .html and .htm files through the PHP handler. You can then use PHP code inside your HTML files:

<!-- This now works in .html files -->
<p>Today's date is: <?php echo date('F j, Y'); ?></p>
Note

The .htaccess change applies to the directory it's in and all subdirectories. If you only want it for a specific subdirectory, place the .htaccess file there instead of in public_html.

02. Which Handler to Use

The correct handler depends on your server's PHP configuration. Ultra Web Hosting uses CloudLinux LSAPI, so the correct handler is:

AddHandler application/x-httpd-lsphp .html .htm

If that doesn't work (you'll see the PHP code displayed as text instead of executing), try these alternatives:

# Alternative 1: Generic PHP handler
AddType application/x-httpd-php .html .htm

# Alternative 2: If using ea-php (EasyApache)
AddHandler application/x-httpd-ea-php82 .html .htm
Tip

If you're not sure which handler your account uses, create a test file called test.html with <?php phpinfo(); ?> as the content. Try each handler in .htaccess until the phpinfo page displays instead of raw PHP code. Delete the test file when done.

03. Parsing Specific Files Only

If you only need PHP parsing in one or two specific .html files (not all of them), you can target them individually:

<Files "contact.html">
  AddHandler application/x-httpd-lsphp .html
</Files>

Or use FilesMatch for a pattern:

<FilesMatch "^(contact|about|pricing)\.html$">
  AddHandler application/x-httpd-lsphp .html
</FilesMatch>

For more .htaccess techniques, see our Complete .htaccess Guide.

04. Performance and SEO Considerations

Performance

When you add the PHP handler for .html files, every .html file is processed by PHP even if it contains no PHP code. This adds a small amount of overhead per request. For a handful of files, it's negligible. For a site with thousands of static .html files, it adds up. Only apply the handler to the directory or files that actually need it.

SEO

Changing how files are processed on the server has zero impact on SEO. Google doesn't care whether a page is served by PHP or as static HTML. The URL stays the same and the output stays the same. The change is entirely server-side and invisible to visitors and search engines.

05. Alternative: Rename to .php

If you're building a new site or can easily update your links, the cleaner approach is to simply rename your files from .html to .php. This is the standard convention and doesn't require any handler configuration.

If you rename files, set up 301 redirects for the old URLs so bookmarks and search engine listings still work:

Redirect 301 /about.html /about.php
Redirect 301 /contact.html /contact.php

Or use a pattern redirect for many files:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.html$ /$1.php [R=301,L]

Need Help With PHP Configuration?

If the handler directive isn't working or you're seeing raw PHP code in the browser, open a support ticket with the directive you tried and the URL that's not working.

Open a Support Ticket

Frequently Asked Questions

How do I make .html files run PHP code?

Add a handler directive to the .htaccess file in your document root so Apache sends .html and .htm files through the PHP interpreter. After adding it, HTML files can contain and execute PHP code.

Which .htaccess handler should I use to parse HTML as PHP?

Use the handler that matches your active PHP version, since the exact directive depends on how PHP runs on the server. If one handler line does not work, check your PHP version in cPanel and use the matching AddHandler or AddType directive, or ask support for the current line.

Can I parse only specific HTML files as PHP?

Yes. Wrap the handler in a Files or FilesMatch block in .htaccess so only the named files are processed as PHP. This avoids the overhead of running every HTML file through PHP when only a few need it.

Does parsing HTML as PHP affect performance or SEO?

Running all HTML through PHP adds a little overhead, so limit it to the files that need it. It does not harm SEO as long as the URLs stay the same, which is the main reason to parse HTML as PHP instead of renaming files to .php and breaking existing links.

Quick Recap: Parse HTML as PHP

If you only do 5 things from this guide, do these:

  1. Add the handler to .htaccess - AddHandler application/x-httpd-lsphp .html .htm
  2. Test with a simple PHP file - <?php echo 'works'; ?> in a .html file
  3. Use <Files> for specific files only - avoids processing all .html files through PHP
  4. Consider renaming to .php instead - cleaner, no handler needed, with 301 redirects for old URLs
  5. Delete test files - never leave phpinfo or test scripts on a live site

Last updated November 2026 · Browse all PHP articles

Share: X in Reddit f Email
  • 527 Users Found This Useful

Was this answer helpful?

Related Articles

Learn About MariaDB

PHP/MySQL | Updated November 2026 Ultra Web Hosting uses MariaDB as the database server on...

How Do I Update or Change My PHP Version

Hosting Control Panel | Updated October 2026 Ultra Web Hosting runs CloudLinux with multiple...

PHP system exec Functions Disabled on Shared Hosting

PHP/MariaDB/MySQL | Updated November 2026 The error "Warning: system() has been disabled for...

phpMyAdmin - Error Incorrect format parameter

PHP/MariaDB/MySQL | Updated March 2026 The "Incorrect format parameter" error in phpMyAdmin...

Register Globals On Off

PHP/MySQL | Updated November 2026 register_globals was a PHP setting that automatically...



Save 30% on web hosting - Use coupon code Hosting30