I'm not sure the best title for this question so sorry if it was confusing.
I have a multi-site install that I regularly add new sites to.
They are generally in the format:
- example.com (default)
I also have a wildcard dns and vshost so I don't have to edit them every time I create a new site:
example.com my.ip.add.ress *.example.com my.ip.add.ress sub3.com my.ip.add.ress <virtualhost *:80> Name example.com alias *.example.com alias sub3.com </virtualhost>
Sites.php has a few entries like:
sites[sub3.com] = 'sub3.example.com'
All of this works great.
Most of these sites are not publicly visible. being disabled with robots.txt and permission preventing users from see them. So I could care less about those. However some sites are public. In the example above the example.com and sub3.com are both public facing sites.
When a user visits rando.example.com the multi-site will send them to example.com but the url will appear as whatever they typed in. Also the sub3.com site will be visible as both sub3.com and sub3.example.com.
How do I, preferably using only Drupal, redirect the non-existent subdomains to the default. Not just show the default but actually do a 301 redirect to the url desired.
To my knowledge I can not solve this with:
- redirect module as it does not let me specify a subdomain or a wildcard. - global redirect does not affect subdomains. - sites.php as it does not redirect but a
sites[*.example.com] => example.com would be cool.
- I understand that I could fix this in the vhost by removing the wildcard name and just adding a new entry for each sub-domain. I do not want to have to edit my vhost every time their is a new sub-domain.
- I understand I may be able to solve this with .htaccess files but I do not want to have to edit that file every time I create a new site either. And I don't really want it to be overridden from default. Plus I have my server pull the file only on reboot and I don't want to reboot apache just to add a site.
- I understand that canonical urls would prevent bots from indexing unused sub-domains but that's not good enough I don't want users using a subdomain that doesn't exist.
My ideal solution would be a redirect that supports sub-domains or something similar. Changes to sites.php or database changes are the goal.