Home > Backend Development > PHP Tutorial > How Can I Make Apache Treat HTML Files as PHP Files Using .htaccess?

How Can I Make Apache Treat HTML Files as PHP Files Using .htaccess?

Barbara Streisand
Release: 2025-01-05 11:00:40
Original
408 people have browsed it

How Can I Make Apache Treat HTML Files as PHP Files Using .htaccess?

How to Use .htaccess to Run HTML Pages as PHP Files

Need a quick solution to run all your HTML files as PHP before a presentation tomorrow? Don't fret; Apache has a solution for you.

(Answer)

To make all .html files run as .php files using Apache, follow these steps:

1. Create a .htaccess File

  • Navigate to the root directory of your website.
  • Create a new file named ".htaccess".

2. Add the Directive

  • Open the .htaccess file in a text editor.
  • Add the following line:
AddType application/x-httpd-php .html .htm
Copy after login
Copy after login

If you're running PHP as CGI, use this instead:

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

Example:

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

This directive tells Apache to treat all files with the extension .html or .htm as PHP files.

Note: If you're using PHP5, you may need to replace "x-httpd-php" with "x-httpd-php5" in the directive.

The above is the detailed content of How Can I Make Apache Treat 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