17 Jan 2007 bi   » (Journeyer)

Towards permalinks all the way

The .tk domain for my Pax Neo-TeX doesn't forward URL paths -- zompower.tk forwards to fzort.org/bi/neo-tech/, but zompower.tk/vote.php won't forward to fzort.org/bi/neo-tech/vote.php. To work around this, I added some PHP at the top of the index page to redirect to the appropriate page if the referrer contains a path to some other page:

<?
$refr = $_SERVER['HTTP_REFERER'];
if (isset($refr)) {
        $refrp = parse_url($refr);
        $rhost = $refrp['host'];
        $rpath = $refrp['path'];
        if (($rhost === 'zompower.tk' ||
             $rhost === 'www.zompower.tk') &&
             $rpath !== '' && $rpath !== '/' && $rpath !== '/index.php') {
                $rfrag = $refrp['fragment'];
                $rqy = $refrp['query'];
                if (isset($rfrag) && $rfrag !== '')
                        $rfrag = '#' . $rfrag;
                else if (isset($rqy) && $rqy !== '')
                        $rfrag = '#' . $rqy;
                header("Location: http://fzort.org/bi/neo-tech" .
                    $rpath . $rfrag);
        }
}
?>

The code also converts query strings (e.g. ?foo) into anchors (e.g. #foo).

This trick may be useful with other forwarding services and web sites as well...

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!