Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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


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

thanks

like image 342
Lelis Avatar asked Jun 14 '11 04:06

Lelis


1 Answers

$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
like image 125
Dos Avatar answered Sep 20 '22 21:09

Dos