Forum Moderators: phranque

Message Too Old, No Replies

Using htaccess to append a header file to every page

         

weldonj

10:15 pm on Oct 22, 2009 (gmt 0)

10+ Year Member



I've been googling around but for the life of me can't figure out how to use htaccess to include a header file before every page.

Ideally I'd like to have a php header file process before every page.

To make matters more complicated I also am processing html files as php with
AddType application/x-httpd-php .htm .html
AddHandler x-httpd-php .htm .html

Anyway to do this?

Receptional Andy

10:19 pm on Oct 22, 2009 (gmt 0)



You can use htaccess to change php configuration, e.g.

php_value auto_prepend_file somefile.php

It wouldn't really be a recommended approach for simple header/footer style includes though.

TheMadScientist

10:19 pm on Oct 22, 2009 (gmt 0)

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



I'm not sure on a Mod_Rewrite solution off the top of my head, and my first inclination is to ask why not just use PHP's include(); since you are parsing everything as PHP anyway?

<?php include $_SERVER['DOCUMENT_ROOT']."the/path/to_your/header.php"; ?>

weldonj

10:40 pm on Oct 22, 2009 (gmt 0)

10+ Year Member



Include is an option. But it's for someone who uses iweb so editing html on every page is a problem.

TheMadScientist

12:51 am on Oct 23, 2009 (gmt 0)

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



I went and looked at iWeb for a minute and it says you can use FTP... I'm not sure if you can upload and set a template with the include in it, so you are basically using a 'custom' template with the include on it, but if you can it should be fairly easy to:

1.) Download the current site.
2.) Do a site-wide find & replace.

Find: <!DOCTYPE
Replace: <?php include "blah"; ?><!DOCTYPE

3.) Upload the site and a new version of the template with the include on it.