Issue
When I use
AddType application/x-httpd-php .phtml .pwml .php5 .php4 .php3 .php2 .php .inc .htm .html
in httpd.conf, the files with the given extensions start being interpreted by PHP interpreter. But all of them also start having 'text/html' MIME type.
I know I can use
<?php header("Content-type: WHATEVER"); ?>
in the files themselves, but is it possible to assign a MIME type right after PHP interpreting for an extension, using the same httpd.conf?
What I want is a way to make any file type being interpreted by PHP, no matter what extension, and don't write header manually, since it always can be inferred from extension. In other words, I want to keep the MIME type a file would have if there wasn't assignment to PHP interpreter.
Solution
By default ie. when: your mime.types does not contain (*):
application/x-httpd-php php
line and your httpd.conf does not contain (**):
PHPIniDir "C:/PHP/"
LoadModule php5_module "C:/PHP/php5apache2_4.dll"
(or similar depending on php's path and apache version)
.. any request to php file will return php's source code (not interpreted) and Apache will not set Content-Type so it is up to your browser how to interpret it (google Mime-type sniffing). Usually you'll just see your source code in the browser's viewport.
If your mime.types contains (*) and httpd.conf does not contain (**) it will tell Apache to serve your php files with Content-Type: application/x-httpd-php. Hovewer it will still be a source code and your browser will ask you whether to open/save requested resource.
In general if your httpd.conf contains (and loads php module this way):
PHPIniDir "C:/PHP/"
LoadModule php5_module "C:/PHP/php5apache2_4.dll"
(or similar depending on php's path and apache version) ... mime.types line:
application/x-httpd-php php
serves slightly different purpose than expected. It no longer provides MIME type for Content-Type: ... HTTP response. It tells Apache which file extensions should be sent to PHP interpreter. You can put to your mime.types the following line:
application/x-httpd-php xyz
and it will tell Apache to send contents of any file with xyz extension to PHP interpreter but your HTTP response will have Content-Type: text/html set and not as you might think application/x-httpd-php.
So you can accomplish what you want by adding this to your mime.types:
application/x-httpd-php phtml pwml php5 php4 php3 php2 php inc htm html
Of course you must have your PHP module loaded.
You may also want to read about mod_rewrite apache module.
Still even if you interpret files with *xyz (whatever) extension as PHP you may freely change content type using:
header('Content-Type: ....');
Answered By - Artur Answer Checked By - Candace Johnson (WPSolving Volunteer)