Home > Backend Development > PHP Tutorial > Can Apache Make HTML Files Execute as PHP?

Can Apache Make HTML Files Execute as PHP?

Patricia Arquette
Release: 2024-12-26 18:32:14
Original
997 people have browsed it

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
Copy after login

For PHP5 as a CGI:

AddHandler application/x-httpd-php .html .htm
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template