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.
Add This to Your .htaccess
Add one line to your .htaccess file in public_html:
- ✓
AddHandler application/x-httpd-lsphp .html .htm
All .html and .htm files in that directory (and subdirectories) will now be processed as PHP.
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>
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
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 TicketQuick Recap: Parse HTML as PHP
If you only do 5 things from this guide, do these:
- Add the handler to .htaccess -
AddHandler application/x-httpd-lsphp .html .htm - Test with a simple PHP file -
<?php echo 'works'; ?>in a .html file - Use
<Files>for specific files only - avoids processing all .html files through PHP - Consider renaming to .php instead - cleaner, no handler needed, with 301 redirects for old URLs
- Delete test files - never leave phpinfo or test scripts on a live site
Last updated March 2026 · Browse all PHP articles
