I need to extract the exact domain name from any Url.
For example,
Url : http://www.google.com --> Domain : google.com
Url : http://www.google.co.uk/path1/path2 --> Domain : google.co.uk
How can this is possible in c# ? Is there a complete TLD list or a parser for that task ?
This means that the URL in question is technically identical to at least one other indexable URL. This could be URLs that are only different based on case, or have the same query string parameters and values (but in a different order).
That “one place” is defined as a location with a unique website address (URL) - so, if the same content appears at more than one web address, you've got duplicate content. While not technically a penalty, duplicate content can still sometimes impact search engine rankings.
You can use the Uri Class to access all components of an URI:
var uri = new Uri("http://www.google.co.uk/path1/path2"); var host = uri.Host; // host == "www.google.co.uk"
However, there is no built-in way to strip the sub-domain "www" off "www.google.co.uk". You need to implement your own logic, e.g.
var parts = host.ToLowerInvariant().Split('.'); if (parts.Length >= 3 && parts[parts.Length - 1] == "uk" && parts[parts.Length - 2] == "co") { var result = parts[parts.Length - 3] + ".co.uk"; // result == "google.co.uk" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With