Home > Backend Development > PHP Tutorial > How Can I Run .html Files as .php Files Using .htaccess?

How Can I Run .html Files as .php Files Using .htaccess?

Linda Hamilton
Release: 2024-12-21 09:41:10
Original
293 people have browsed it

How Can I Run .html Files as .php Files Using .htaccess?

Running .html Files as .php Using .htaccess

Question:

How can I execute all my .html files as .php files without manually modifying the file extensions?

Answer:

To achieve this, you can leverage Apache's .htaccess file. By creating a .htaccess file at the root of your website and adding the following line, you can instruct Apache to treat .html files as PHP files:

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

This directive translates to Apache, "Whenever a request is made for a .html or .htm file, Apache should execute the file как if it was a PHP file."

Alternatively, if you're running PHP as CGI, you should modify the AddType directive to:

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

With this configuration in place, Apache will automatically interpret all .html and .htm files as PHP code, eliminating the need to change the file extensions or re-link any pages.

The above is the detailed content of How Can I Run .html Files as .php Files Using .htaccess?. 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