Home >Backend Development >PHP Tutorial >Can Apache Make HTML Files Execute as PHP?
Can Apache "Deceive" Browsers into Treating HTML Files as PHP?
To avoid the tedious task of manually updating file extensions, it's possible to leverage Apache's .htaccess configuration file to achieve a "shortcut" and execute all .html files as .php files.
Solution
At the root of your website, create a file named ".htaccess" and add the following line:
For Apache2 on Ubuntu/Debian:
AddType application/x-httpd-php .html .htm
For PHP5 as a CGI:
AddHandler application/x-httpd-php .html .htm
This directive instructs Apache to recognize all files with the extensions .html and .htm as PHP files, triggering the PHP interpreter for execution. This will allow the server to interpret and execute your .html files as if they were .php files.
The above is the detailed content of Can Apache Make HTML Files Execute as PHP?. For more information, please follow other related articles on the PHP Chinese website!