Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking to see if two URLs are equivalent [duplicate]

Tags:

c#

url

Possible Duplicate:
Check if 2 URLs are equal

Sometimes there are differences in ways that urls are typed but at the end they are equivalent. For example capital letters can be converted to lower case and a forward slash at the end or the url can be removed. As an example the two URLs are equivalent:

  • www.myUrl.com
  • http://www.myURL.com/

I am wondering what is the best way to make sure that two URLs are equivalent? what conditions are sufficient to make sure that two urls are pointing to the same document? (I am coding in C# so it would be nice to see if there is a library that can do that too)

Thanks

like image 600
Mark Avatar asked Nov 18 '12 23:11

Mark


1 Answers

Just look at the Uri library. For example you could compare by doing the following:

  • http://msdn.microsoft.com/en-us/library/system.uri.aspx

For example:

Uri uri1 = new Uri(url1);
Uri uri2 = new Uri(url2);

// Check urls
if (uri1.AbsolutePath == uri2.AbsolutePath)
{
    // Urls match
}

You might also need to first look into doing URL Normalization:

  • http://en.wikipedia.org/wiki/URL_normalization
like image 148
skub Avatar answered Nov 09 '22 22:11

skub