Forum Moderators: phranque

Message Too Old, No Replies

Why auto prepend file needs AddHandler?

auto_prepend_file does not work without AddHandler

         

smallcompany

8:37 pm on Mar 27, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Why is that?

Among other, I have these lines in PHP.INI:
include_path = ".:/path/public_html"
auto_prepend_file = "/path/public_html/track/script.php"


The script writes some referrer data into a cookie. It works fine as long as I have these or similar (depending on the server) directives in .htaccess:
AddHandler application/x-httpd-php .html
AddType x-mapp-php .html


If the script is pure PHP as it is, why such AddHandler directives seem to be mandatory?

Little background:
To be honest, I don't mind using such unless they affect how my website works. In this particular case, those directives cause IE9 to download instead of render the page. Firefox works fine. If I change them to this (note that 5 for PHP):
AddHandler application/x-httpd-php5 .html
AddType x-mapp-php5 .html


IE9 works fine, but then those directives cause the server to return duplicated content on requests with trailing slash. Example: somepage.html/something returns somepage.html with broken links which create new duplicate pages and so on. With one website, after I stopped this, Google is asking for 13K pages while the website has around 300.

The initial question is based on a trouble with CGI based server. On others where PHP is configured to run as Apache, I can use AddHandler and directive AcceptPathInfo Off which turns those slashes OFF and returns 404 as it should be.
Background ends.

So yeah, why that AddHandler is needed for PHP scripts that are set to run with auto_prepend_file in PHP.INI? Later on, PHP seem to work fine (I know this based on the exit PHP scripts/redirects).

Thanks

coopster

1:23 am on Apr 6, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



AddHandler is how Apache and PHP work together. The other directives like AcceptPathInfo can be handy but you are correct, you have to develop your applications with this in mind. Another directive that you may need to consider here is MultiViews.

The balance works great when configured properly, you just need to get them all in synch and if you are on a shared host it becomes much more difficult.

smallcompany

1:34 am on Apr 6, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I just thanked you in PHP forum:
[webmasterworld.com...]

This topic has been such a headache for me, and is soooo overlapping between Apache and PHP that I ended posting in both forums and had some of my posts moved by admins.

In any case, I just explained how far I got, including some of the stuff that I learned.

Thanks again.