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

How Can I Temporarily Serve .html Files as .php Files Using .htaccess?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-20 07:26:09761browse

How Can I Temporarily Serve .html Files as .php Files Using .htaccess?

Serving .html as .php with .htaccess

In a situation where it's not feasible to manually update all .html files to run as .php before a presentation, you can leverage Apache's .htaccess file to achieve this temporarily.

To do this, you need to:

  1. Create .htaccess: Create a file named ".htaccess" in the root directory of your website.
  2. Add directive: Add the following line to the .htaccess file:
[Apache2 @ Ubuntu/Debian:]
AddType application/x-httpd-php .html .htm
[PHP5:]
AddType application/x-httpd-php5 .html .htm
[PHP as CGI:]
AddHandler application/x-httpd-php .html .htm 
  1. Restart Apache: Once you've added the directive, restart your Apache server to apply the changes.

With this setup in place, all .html files within your website will be interpreted and processed as .php files. This provides a quick and temporary solution to run your .html pages as .php without modifying their file extensions or content. Remember, this is a workaround and not a permanent solution.

The above is the detailed content of How Can I Temporarily Serve .html Files as .php Files Using .htaccess?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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