I have a table that contains a list of websites.
I have a sql variable @url, I want to select all the rows where the website is equal to @url. However, if there is no subdomain I want to match www and the root domain.
So, if @url='http://website.com' it should match both 'http://website.com' and 'http://www.website.com'
I'm currently doing
select * from websites a
where b.archived = 0
and @url like replace(a.WebsiteURL, '*', '%')
order by newid()
Obviously that doesn't take into account the www issue.
Any ideas how to solve this problem?
I was thinking of force adding the www. if it doesn't exist (and the url doesn't have a subdomain) before adding it to the DB. But, what about websites that actually don't have the www and redirect the www to the root?