Jump to content

modify_url leaving double slash in url // ?


DSchragg

Recommended Posts

Can someone tell me what's wrong with this?

 

I'm trying to remove any folders listed in the url but maintaining the rest of the structure....

Example: http://example.com/test/test.php changes to http://example.com/test.php

 

My current config is removing the folder but leaving a double slash - i.e. http://example.com//test.php

 

Any help is greatly appreciated!

 

<?php
function modify_url($mod)
{
    $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    $query = explode("/", $_SERVER['QUERY_STRING']);
    // modify/delete data
    foreach($query as $q)
    {
        list($key, $value) = explode("/", $q);
        if(array_key_exists($key, $mod))
        {
            if($mod[$key])
            {
            }
            else
            {
                $url = preg_replace('/&?'.$key.'wp'.$value.'/', '', $url);
            }
        }
    }
    // add new data
    return $url;
}


$url = modify_url(array('' => ''));

?>

<?php echo $url ?>

Link to comment
https://forums.phpfreaks.com/topic/213576-modify_url-leaving-double-slash-in-url/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.