how to remove multiple slashes in URI with 'PREG' or 'HTACCESS'

后端 未结 5 2124
滥情空心
滥情空心 2021-01-04 21:51

how to remove multiple slashes in URI with \'PREG\' or \'HTACCESS\'

site.com/edition/new/// -> site.com/edition/new/


site.com/edition///new/ -> site.co

5条回答
  •  耶瑟儿~
    2021-01-04 22:34

    $url = 'http://www.abc.com/def/git//ss';
    $url = preg_replace('/([^:])(\/{2,})/', '$1/', $url);
    // output http://www.abc.com/def/git/ss
    
    $url = 'https://www.abc.com/def/git//ss';
    $url = preg_replace('/([^:])(\/{2,})/', '$1/', $url);
    // output https://www.abc.com/def/git/ss
    

提交回复
热议问题