I have a small php script for url redirection. I'm not a programmer, the script is composed by a freelancer a few years ago, but now I'm unable to contact him. I recently migrate my website to another server and start getting errors due to this script. I try some basic tricks I know but I'm unable to avoid errors. I will appreciate any ideas
Here is the script:
if(!empty($_GET['idsub'])||!empty($_GET['idsub2'])||!empty($_GET['idf'])||!empty($_GET['idp']))
header("Location: /_".preg_replace('/\.php$/','',$_GET['idsub'])."/_".preg_replace('/\.php$/','',$_GET['idsub2'])."/_".preg_replace('/\.php$/','',$_GET['idf'])."/_".preg_replace('/\.php$/','',$_GET['idp']).($_GET['page']?"?page=".$_GET['page']:''),301);
if($_GET['idp']=='.php')unset($_GET['idp']);
if($_GET['idsub']=='.php')unset($_GET['idsub']);
if($_GET['idsub2']=='.php')unset($_GET['idsub2']);
if($_GET['idf']=='.php')unset($_GET['idf']);
if($_GET['demmi']!='true' && (!empty($_GET['idsub'])||!empty($_GET['idsub2'])||!empty($_GET['idf'])||!empty($_GET['idp']))){
$key=(empty($_GET['idf'])?'':'1').(empty($_GET['idsub'])?'':'2').(empty($_GET['idsub2'])?'':'3').(empty($_GET['idp'])?'':'4');
$vals=(empty($_GET['idf'])?'':'/'.preg_replace('/.php$/','',$_GET['idf'])).(empty($_GET['idsub'])?'':'/'.preg_replace('/.php$/','',$_GET['idsub'])).(empty($_GET['idsub2'])?'':'/'.preg_replace('/.php$/','',$_GET['idsub2'])).(empty($_GET['idp'])?'':'/'.preg_replace('/.php$/','',$_GET['idp']));
$vals=preg_replace('/\/([^\/]*)$/','./$1',$key.$vals);
header("Location: /$vals".(empty($_GET['page'])?'':'?page='.$_GET['page']),301);
}
if($_GET['demmi']=='true' )
{
$key=str_split($_GET['key']); $i=0;
$vals=explode('/',str_replace('./','/',$_GET['vals']));
foreach($key as $h)
{switch($h)
{case '1': $_GET['idf']=$vals[$i].'.php'; break;
case '2': $_GET['idsub']=$vals[$i].'.php'; break;
case '3': $_GET['idsub2']=$vals[$i].'.php'; break;
case '4': $_GET['idp']=$vals[$i].'.php'; break;}
$i++;}
}
$idf=$_GET['idf'];
$idsub=$_GET['idsub'];
$idsub2=$_GET['idsub2'];
$idp=$_GET['idp'];
$page=$_GET['page'];
if (isset($page)) {
$page=$page;
} else {
$page=1;
}
And here are the errors I get:
PHP Notice: Undefined index: idp in /home/typol0/public_html/control/index.php on line 5
PHP Notice: Undefined index: idsub in /home/typol0/public_html/control/index.php on line 5
PHP Notice: Undefined index: idsub2 in /home/typol0/public_html/control/index.php on line 5
PHP Notice: Undefined index: idf in /home/typol0/public_html/control/index.php on line 5
PHP Notice: Undefined index: demmi in /home/typol0/public_html/control/index.php on line 7
PHP Notice: Undefined index: demmi in /home/typol0/public_html/control/index.php on line 14
PHP Notice: Undefined index: idf in /home/typol0/public_html/control/index.php on line 25
PHP Notice: Undefined index: idsub in /home/typol0/public_html/control/index.php on line 26
PHP Notice: Undefined index: idsub2 in /home/typol0/public_html/control/index.php on line 27
PHP Notice: Undefined index: idp in /home/typol0/public_html/control/index.php on line 28
PHP Notice: Undefined index: page in /home/typol0/public_html/control/index.php on line 29