Running PHP code in .html files
Ce contenu n’est pas encore disponible dans votre langue.
By default, PHP code only runs in files ending in .php. In a .html or .htm file, PHP code isn’t run: visitors may see the code itself, or nothing at all.
Option 1: Rename the files to .php (recommended)
Section titled “Option 1: Rename the files to .php (recommended)”Renaming about.html to about.php is the simplest and fastest option, because the server doesn’t have to check every HTML page for PHP code.
To keep your old addresses working, add a redirect to the .htaccess file in the same folder:
RewriteEngine OnRewriteRule ^(.*)\.html$ /$1.php [R=301,L]Update the links in your pages to point to the .php files too.
Option 2: Tell the server to run PHP in .html files
Section titled “Option 2: Tell the server to run PHP in .html files”- In cPanel’s File Manager, open your website’s folder, for example
public_html. Click Settings and tick Show Hidden Files. - Edit the
.htaccessfile (create it if it doesn’t exist) and add this line at the top:
AddHandler application/x-httpd-lsphp .html .htm- Open one of your
.htmlpages in your browser to check that the PHP code runs.
This uses the PHP version you’ve chosen in Select PHP Version.
Related articles
Section titled “Related articles”Cette page vous a-t-elle aidé ?
Merci pour votre retour.