1

I would like to convert a URL like this: http://www.google.com to this google.com. So if the format of the URL is like this http://google.com it will be converted to this google.com

I need to determine if two urls are the same no matter the format of the URL. Is there a way to do this. I am using the Uri library in C# but the host value is different for http://www.google.com and http://google.com

Luke101
  • 63,072
  • 85
  • 231
  • 359
  • 6
    `www.google.com` and `google.com` *are* different. It's not just a matter of formatting. One just happens to redirect to the other. – dtb Aug 16 '11 at 18:39
  • 1
    What dtb said. There are even instructions on how to use a 301 Redirect to force the non-www to go to the www: http://www.stepforth.com/resources/web-marketing-knowledgebase/non-www-redirect/ – JeffH Aug 16 '11 at 18:40
  • 1
    Note that "domain.com" and "www.domain.com" do not have to show the same website... – David Aug 16 '11 at 18:40

1 Answers1

5

You can use the Uri class to parse URIs.

Example: Get just the domain name from a URL?

You can extract more than the host name, too. Here is a full list of properties you can get from a Uri instance: http://msdn.microsoft.com/en-us/library/system.uri_properties(v=VS.71).aspx

Community
  • 1
  • 1
Chris Laplante
  • 29,338
  • 17
  • 103
  • 134