<?php// Process supplied parameters as direct link (link to some deep place// in the web structure).//// This script is usualy called via mod_rewrite when user enter// no page with some parameter.//// (c)miho2007 / www.mlab.cz// Clear variablesunset($Redirect);unset($RedirectUpper);unset($RedirectToPage);unset($Lang);// Include redirect definitions (as an array)include_once("DirectLink.inc");// Do all upcaseforeach($Redirect as $Key => $Value){$RedirectUpper[strtoupper($Key)]=$Value;}// Process language$Lang=$_SERVER[SCRIPT_FILENAME];$Lang=preg_replace("/(?:.+)\.(.+)\.(.*)/i","$1",$Lang);if ($Lang==$_SERVER[SCRIPT_FILENAME]) $Lang="";// Find redirect$RedirectToPage=$RedirectUpper[strtoupper(urldecode($_SERVER[QUERY_STRING]))];// If not found -> list all posibilitiesif ($RedirectToPage==""){// File Nameif ($Lang=="")$Lang="en";$FileName="DirectLink.$Lang.tmpl";// Read Template$Template=@file($FileName);// Trim Linesif ($Template<>FALSE){foreach($Template as $Key => $Line){$Template[$Key]=rtrim($Line);}$Template=implode("\n",$Template);}// Generate List$Table ="";$Table.="<table>\n";$Table.=" <tr>\n";$Table.=" <th> Direct Link </th>\n";$Table.=" <th> Redirected to </th>\n";$Table.=" </tr>\n";foreach($Redirect as $Key => $Value){$Table.=" <tr>\n";$Table.=" <td> $Key </td>\n";$Table.=" <td> $Value </td>\n";$Table.=" </tr>\n";}$Table.="<table>\n";// Put it into Templateif ($Template<>"")print str_ireplace("<<Table>>", $Table, $Template);elseprint $Table;// Finishedreturn 0;}else{if ($Lang<>"")if (file_exists($_SERVER["DOCUMENT_ROOT"].$RedirectToPage.".".$Lang.".html"))$RedirectToPage.=".".$Lang.".html";}// Redirect pageheader("HTTP/1.1 301 Moved Permanently");header("Location: ".$RedirectToPage);header("Connection: close");?>