Forum Moderators: phranque
[webmasterworld.com...]
Only difference is that neither AddHandler or AddType did the trick for me. In fact, when I tried AddType, and navigated back to the HTML page that contained the PHP, FF prompted me to Open/Save the file (and ironically enough - view it in IE).
In IE, as expected, didn't work either as I got the unparsed PHP code in raw HTML. My htaccess file only has the following lines:
Options +MultiViews
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
I guess the order doesn't matter in that particular case. Any ideas?
Regards.
For PHP issues, you may get better answers in our PHP forum, and there are several "PHP setup troubleshooting" threads in the PHP section of our library as well.
Jim
I tried many different combinations of the two directives, including:
AddType text/html .php
AddHandler application/x-httpd-php .html
But none worked. This one does:
AddType text/html .php
AddHandler php-script .php .html
Options +MultiViews
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Now I can use PHP within my HTML which is parsed properly as if it was a PHP file. I am not sure if I need .php in my php-script declaration - isn't that assumed? To be quite honest I don't know why I use php-script in first place - with the only good reason that it seems to be doing the job. I don't understand why application/x-httpd-php didn't work and why php-script did. Can anyone confirm that this directive doesn't have any other undesirable effect. As far as I can say, .html pages load fine (including the few ones that include PHP), but also a few .php files also parse properly.
If I was to be 100% satisfied (currently 95%) it would be if there was a way to have a condition which would allow *only* HTML that contains PHP to be parsed as PHP. At the moment, if I am not mistaken, every .html is parsed as PHP. The delay, if any, seems to be very tiny.
Thanks so much Jim for pointing me to the right direction!
Regards.
Because the definition of the "application" MIME-type is that resources of that type are to be processed by a client-side application programs. A simple example would be a .xls file to be passed to the MS Excel application program on the client. So, PHP code tagged with "application" gets passed straight through to the client (the browser) to be processed on the client side. Because the browser can't "run" PHP, it throws a download dialog. In short, the server did what you told it to do.
> If I was to be 100% satisfied (currently 95%) it would be if there was a way to have a condition which would allow *only* HTML that contains PHP to be parsed as PHP. At the moment, if I am not mistaken, every .html is parsed as PHP. The delay, if any, seems to be very tiny.
Unless you explicitly tell it, there's no way for the server to know that an HTML file contains PHP (or SSI, for that matter) without parsing it -- reading, analyzing, and interpreting its contents. Again, that's the definition of "parsing."
You could give those PHP-containing files a distinct name, such as the traditional ".shtml", and then tag only .shtml files to be parsed by the script handler.
Jim