WebGee DocsDocs
Development

Run PHP inside .html files

Make the server execute PHP in files with a .html or .htm extension, using the correct handler for WebGee's LiteSpeed setup.

Make .html and .htm files execute PHP. Applies to shared, reseller and Premium hosting.

This is usually needed when adding a contact form to an existing static site whose URLs you do not want to change.

Consider whether you need this. Renaming the file to .php and adding a redirect from the old URL keeps the default handler and is one less thing to maintain. This is the right answer when the URL genuinely cannot change.

The rule to use

WebGee servers run LiteSpeed with CloudLinux, so this is the handler that applies. Create or edit .htaccess in your document root and add:

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

Save. It takes effect immediately.

Check it worked

Create test.html in your document root:

<?php echo "PHP is running in .html files"; ?>

Visit https://example.com/test.html. You should see the sentence. If you see the raw PHP code instead, the handler is not applied.

Delete test.html afterwards.

If it does not work

Older documentation suggests these, which apply to Apache with different PHP handlers and are not what WebGee runs:

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

Try that only if the LiteSpeed handler above does nothing. If neither works, open a ticket rather than stacking more rules — conflicting handlers produce a 500 error that is harder to diagnose than the original problem.

You may also need file permissions of 644 on the affected files; 755 is only required for directories.

What this costs

Every .html file on the site is now parsed by PHP, including purely static ones. That is slower than serving them directly and prevents them being cached as efficiently. Apply it to a specific directory rather than the whole site where you can, by putting the .htaccess in that directory instead.

On this page