File: D:/HostingSpaces/SBogers57/topsluchtfilters.nl/wwwroot/config/friendlyUrl.php
<?php
/**
* friendlyUrl.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 3/19/13
*/
function initFriendlyUrl($urlCountStart = 0, $addLanguage = 0)
{
/**
* 1. Get the REQUEST_URI and explode this on '/'
*/
$stringUrl = substr($_SERVER['REQUEST_URI'],1);
$urls = explode('/', $stringUrl);
/**
* Optional - redirect short links to the right page
*/
if(strtolower($urls[0]) == 'iso16890'){
$location = $_SERVER['HTTP_HOST'];
$location .='/nl/normeringen/ISO16890';
// redirect to ISO detail page
header('Location: http://'.$location);
exit;
}
if(strtolower($urls[0]) == 'infographic'){
$location = $_SERVER['HTTP_HOST'];
$location .='/public/docs/ISO16890_infographic_-_TOPS_Luchtfilters.pdf';
// redirect to ISO detail page
header('Location: http://'.$location);
exit;
}
if(strtolower($urls[0]) == 'junior-logistiek-medewerker'){
$location = $_SERVER['HTTP_HOST'];
$location .='/200115_vacature_tops-website.pdf';
// redirect to ISO detail page
header('Location: http://'.$location);
exit;
}
if(strtolower($urls[0]) == 'klantenservice-en-aanpakker'){
$location = $_SERVER['HTTP_HOST'];
$location .='/klantenservice-en-aanpakker.pdf';
// redirect to ISO detail page
header('Location: http://'.$location);
exit;
}
/**
* 2. If we have a language, the structure will be root.com/lang/page/sub/sub2/sub3
* Check if the lang is valid, else header 404.
* If no language is set, header to "nl".
*/
$urlCount = $urlCountStart;
if($addLanguage)
{
$languages = array('nl','en','de');
$default = $languages[0];
if(isset($urls[$urlCount]) && ! empty($urls[$urlCount]))
{
$lang = trim(urldecode($urls[$urlCount]));
if(in_array($lang,$languages))
{
define('URL_LANG', $lang);
define('LANG_ROOT', SITE_ROOT . $lang . '/');
}
else{
define('LANG_ROOT', SITE_ROOT . $default . '/');
Func::notFound();
}
}
else{
// redirect to default page
header ('HTTP/1.1 301 Moved Permanently');
header('Location: ' . SITE_ROOT . $default . '/');
exit;
}
$urlCount++;
}
/**
* 3. The second - or first if ! $addLanguage - GET-variable is $page
*/
if(isset($urls[$urlCount]) && ! empty($urls[$urlCount]))
{
$page = trim(urldecode($urls[$urlCount]));
if(!empty($page))
{
define('URL_PAGE', $page);
$urlCount++;
}
}
/**
* 4. All the other get variables are called sub, sub2, sub3 etc.
*/
$subtract = $addLanguage + $urlCountStart;
if(count($urls) > $urlCount)
{
for($i=$urlCount;$i<=count($urls);$i++)
{
if(isset($urls[$i]))
{
$value = trim(urldecode($urls[$i]));
$name = 'URL_SUB';
if($i > $urlCount) $name.= $i-$subtract; // bv. -kms & -lang = -2
if($value != '')
{
define($name,$value);
}
}
}
}
}