Just a quicky really. I want to be able to redirect anybody who types a subdomain.mydomain.com
to be redirected to a page on my main domain. i.e If I typed: answers.mydomain.com
I would be redirected to mydomain.com/suberror
for instance.
I would like this to be a universal rule if possible because I thought it would be easier to add statements to exclude any subdomains that I didn't want to be redirected rather than add statements to include every other subdomain. I will need to this using a .htaccess
file by the way.
Please could you tell me if this is possible, and if so, how.... Thanks in advance!
Try adding this to an appropriate place in your .htaccess file:
As long as the requested host is
answers.mydomain.com
, the rule will be applied. With the regex match set to^
, any URI will match and the target will be redirected to http://mydomain.com/suberrorIf you want only specific URI requests to be redirected to /suberror, you can tweak the
^
to something appropriate.EDIT:
For all subdomains (including www.mydomain.com):
To exclude www.mydomain.com, add this line before the RewriteRule: