Prepend and Append Files with .htaccess
One of the lessor known and used capabilities of .htaccess files is the ability to prepend and append includes to every page request. Doing so avoids needing to code <?php require('footer.php'); ?>
in every template file you wat to use them in. Here's the .htaccess code:
# Prepend the file
php_value auto_prepend_file "/dir/path/utilities.php"
# Append file to bottom of page
php_value auto_append_file "/dir/path/templates/footer.php"
Now don't mistake this post as me telling you to use this strategy; using this functionality creates a layer of indirection that could confuse a team of developers if they don't all have a grasp of where automatically included files are coming from. Just wanted to let you know this was possible!
With Firefox OS, asm.js, and the push for browser performance improvements, canvas and WebGL technologies are opening a world of possibilities. I featured 9 Mind-Blowing Canvas Demos and then took it up a level with 9 Mind-Blowing WebGL Demos, but I want to outdo...
Many of the new APIs provided to us by browser vendors are more targeted toward the mobile user than the desktop user. One of those simple APIs the Vibration API. The Vibration API allows developers to direct the device, using JavaScript, to vibrate in...
I was inspired when I first saw Addy Osmani's original ShineTime blog post. The hover sheen effect is simple but awesome. When I started my blog redesign, I really wanted to use a sheen effect with my logo. Using two HTML elements and...
One subtle detail that can make a big difference on any web design is the use of image reflections. Using them too often can become obnoxious but using reflections on large, "masthead" images is a classy enhancement. Unfortunately creating image reflections within your...
this strategy is often used to hook a profiler into an existing app, which works great in DEV environments
see e.g. http://xhprof.io/
I can see it now, the /html directory full of code snippets, and an incredibly convoluted htaccess file that conditionally assembles the various pages for a site. :)
Quick! Turn it into a framework!
I’ve used to use this technique, but dropped it for a while now.
It appears very useful at first but can be dangerous actually…
One of its weakness is the impossibility to “un” prepend or “un” append according to directory or filematch directives.
How can i use the .httaccess pre-append a .php file? i have tried using—– php_value auto_prepend_file “inc.php”
Am getting this error: Fatal error: Unknown: Failed opening required ‘inc.php” (include_path=’.;D:\xampp\php\PEAR’) in Unknown on line 0
@Matthew
have you tried using full path like /var/www/site/dir/file.php?
.htaccess – is a single file for all project. And I think it’s a bad practice to prepend files, because they will prepend on all pages.
I find it hard to believe @ Pluto htaccess allows if statements.
Thanks Chris, this would be a great way to append a “copyright link” that can’t easily be found.