Syntax based normalization of URL's

Installs: 9 997

Dependents: 1

Stars: 55

Watchers: 2

Forks: 11

Open Issues: 2

Language: PHP

1.4.0 2015-06-11 16:06 UTC


This normalizes URI's based on the specification RFC 3986

Example usage:

require_once 'vendor/autoload.php';

$url = 'eXAMPLE://a/./b/../b/%63/%7bfoo%7d';
$un = new URL\Normalizer( $url );
echo $un->normalize();

// result: "example://a/b/c/%7Bfoo%7D"

The normalization process preserves semantics so, for example, the following URL's are all equivalent:

HTTP:// and and and and and and[key]=value and

The following normalizations are performed:

  1. Converting the scheme and host to lower case
  2. Capitalizing letters in escape sequences
  3. Decoding percent-encoded octets of unreserved characters
  4. Adding trailing /
  5. Removing the default port
  6. Removing dot-segments

For more information about these normalizations, please see the following Wikipedia article:

For license information, please see LICENSE file.


Two options are available when normalizing URLs which are disabled by default:

  1. Remove empty delimiters. Enabling this option would normalize to Currently, only the query string delimiter (?) is supported by this option.
  2. Sort query parameters. Enabling this option sorts the query parameters by key alphabetically. For example, becomes


Add further scheme-based normalization steps, as detailed in section 6.2.3 of the RFC.