wood_menu My Weblog My Gallery About me Contact me
Follow me on twitter

Apache : Inject HTTP response header in a rewrited URL using environment variable

I've spent a few hours looking for a way to inject HTTP response headers in a rewrited URL directly from the Apache configuration.

Here's the trick, in the RewriteRule just set a environment variable, ie: "addheader".
But unfortunately, this one can't be used as-is as a condition in the "Header" directive. In this case you'll need to rely on the presence / absence of the "REDIRECT_addheader" :

RewriteEngine On
RewriteRule ^([A-Z]{2})_([a-z]{2})$  /rewrite.php?a=$1&b=$2 [L,E=addheader:1]
Header set my-header "myvalue" env=REDIRECT_addheader

Posted by Alexandre De Dommelin on Tue Nov 22 20:11:31 UTC 2011 | Permanent link | File under: Tips

Puppet Talk @ Journées du Logiciel Libre 2011

Here are the slides of the talk I've given at Journées du Logiciel Libre yesterday in Lyon (Download)


Posted by Alexandre De Dommelin on Sat Nov 19 10:31:32 UTC 2011 | Permanent link | File under: Foo

Parse .ini files with bash and sed

Here's a very cool way to parse ini files inside a shell script.
The following snippet will declare variables in the current scope of your script from all the key/values pairs present in the matching section.

#!/bin/bash
CONFIG_FILE="config.ini"
SECTION="section_1"

eval `sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
    -e 's/;.*$//' \
    -e 's/[[:space:]]*$//' \
    -e 's/^[[:space:]]*//' \
    -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" \
   < $CONFIG_FILE \
    | sed -n -e "/^\[$SECTION\]/,/^\s*\[/{/^[^;].*\=.*/p;}"`

Posted by Alexandre De Dommelin on Wed Oct 19 18:41:31 UTC 2011 | Permanent link | File under: Tips