I am developing a site that will allow users to enter URLs that may link internally or externally. I want to visually indicate external links differently than internal ones. I could bang out some code that does this with brute force, but before I do I am wondering if there is a simple way to do this.
Say my site is “www.mysite.com”, then “mysite.com/somepath”, “http://mysite.com/somepath“, “http://www.mysite.com/somepath” should all resolve as internal URLs, ideally I would also get a resultant string that is just the relative path “/somepath”.
Any suggestions?
Use the Uri class to parse and normalize your URLs. After that, it’s easy to check if they start with some base URL.