Remove filename from URL path

$main_url = $_SERVER[‘HTTP_REFERER’] ;
$url_explode = explode(“/”, $main_url);
$file_name = end($url_explode);
$file_explode = explode(“.”, $file_name);
$quest_explode = explode(“?”, $file_name);

if(count($file_explode) > 1){
$end_is_file = $file_explode[1];
}
else{
$end_is_file = “”;
}

if(count($quest_explode) > 1){
$end_is_quest = $quest_explode[1];
}
else{
$end_is_quest = “”;
}

if ($end_is_file!= “”){
$result_url = str_replace($file_name, “”, $main_url);
$url = $result_url;
}
elseif ($end_is_quest!= “”){
$result_url = str_replace($file_name, “”, $main_url);
$url = $result_url;
}
else{
if(substr($main_url,-1,1)!= “/”){
$main_url .= “/”;
}
$url = $main_url;
}

Leave a Reply

Your email address will not be published. Required fields are marked *