"how do i apply url normalization rules in php?" Answer’s

0

The Pear Net_URL2 library looks like it'll do at least part of what you want. It'll remove dot segments, fix capitalization and get rid of the default port:

include("Net/URL2.php");
$url = new Net_URL2('HTTP://example.com:80/a/../b/c');
print $url->getNormalizedURL();

emits:

http://example.com/b/c

I doubt there's a general purpose mechanism for adding trailing slashes to directories because you need a way to map urls to directories which is challenging to do in a generic way. But it's close.

References:

  • http://pear.php.net/package/Net_URL2
  • http://pear.php.net/package/Net_URL2/docs/latest/Net_URL2/Net_URL2.html
Wednesday, March 31, 2021
 
treeface
answered 11 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :