Auto_Prepend / Append Via Apache Directive

By Deane Barker on May 4, 2004

HTACCESS Wrappers with PHP: Really interesting technique of using Apache directives to have Apache send Web requests to PHP scripts. You can do this already via auto_prepend and auto_append files, but it’s interesting to see someone do this via Apache directive rather than php.ini configuration.

To start off, make a folder on your web host called “header”. Create a new text file and enter the following:

AddHandler headered .htm
AddHandler headered .html

Action headered /header/header.php

I’ve tried very hard to find a point to this, rather than using php.ini configuration, but I can’t. The only thing I can think of is to prevent programmers from overriding auto_prepend or auto_appened directives in an .htaccess file. But why?

Gadgetopia

Comments

  1. I was using auto_prepend in my .htaccess file until my web host migrated to suexec, now it doesn’t work.

  2. The point of this suddenly hit me — using this, you can execute PHP scripts for ANY request to ANY file. autoprepend and autoappend only work when the target file is an executable PHP script.

    I tested it, and it works great — the URL is to a JPG, but it’s intercepted by the PHP page. Handy.

  3. Yes, it works. Using this I made auth password requiment for some kinds of files. The file path must be absolute path to $DOCUMETROOT, otherwise only you need the PHP file in every subdirectory of $DOCUMENTROOT.

  4. Hey, one great reason for this functionality even for php setups is that it will allow you do have autoprepend and autoappend files for individual virtual hosts. That way, if you serve many different php websites with the same server, then each one can have its own autoprepend and autoappend files.

  5. Sadly, it doesn’t look like this is a strait-up replacement for autoprepend and autoappend as it can’t be used with PHP files.

    However, if one has the modextfilter module installed, one could rewrite any incoming request, process it, reroute it, prepend and append it: http://httpd.apache.org/docs/2.0/mod/modextfilter.html

    Much more power, too, I believe–though, as with most powerful things, it’s not widely available.

Comments are closed. If you have something you really want to say, email editors@gadgetopia.com and we‘ll get it added for you.