This gem can normalize HTTP(S) URLs by applying a certain set of transformations. After normalization, two different URLs that point to the same resource should look exactly the same.
will all become
http://example.com/products?product_id=123 after normalization.
Some of the transformations are potentially dangerous, since not all webservers comform to standards and some of them are just plain weird. So there is no gurantee that the URL will still work.
Add this line to your application's Gemfile:
And then execute:
Or install it yourself as:
$ gem install normalize_url
.("http://example.com/products/?foo=bar&baz") # => "http://example.com/products?baz&foo=bar"
Some tranformations could be skipped by demand. All you need is to pass its
name as a optional value to
.("http://example.com/foo/") # => "http://example.com/foo" .("http://example.com/foo/", remove_trailing_slash: false) # => "http://example.com/foo/"
Remove trailing slash. Option
Remove repeating slashes. Option
Remove hash fragment. Option
Remove known commonly used tracking query parameters. Option
Sort query string. Option
- Fork it (https://github.com/rwz/normalize_url/fork)
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create a new Pull Request