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
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
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!