I'm using IIS7 and the URL Rewrite module.
I would like to use regex to match any subdomain apart from www.
So...
frog.domain.co.uk = Match
m.domain.co.uk = Match
anything.domain.co.uk = Match
www.domain.co.uk = No match
This way I can redirect any subdomain that someone types in back to www.
you can use 301 in .htaccess for this.
Use this rule -- it will redirect to
www.exmaple.com
domain if domain is different:You can optimize it a bit if you do not want to type domain name twice (
example.com
) -- but that is very minor thing and depending on your circumstances/configuration it is can be undesired.This will match what you want:
Which is a negative lookahead for
www.
. Not sure if you need the trailing.*