Forum Moderators: phranque
In particular, my need is that I am interested in "wildcard" subdomains since I am trying to grab traffic going to old and unknown sub-domains which were in use by the old site owners (therefore do not know the old sub-domain names), but want the wildcard traffic sent to my index page so it is not lost.
P.S. If possible, would love to be able to do this using htaccess but tried various htaccess files and none of them worked with wildcard subdomains, unless I am missing something. Could be since I am not too good with htaccess.
First things first, have you verified that wildcard DNS has been configured for the domain that you are looking to capture?
Secondly, once you are sure that a request for anything.example.com is resolving to the IP address of your server you still need to get through the Apache config (if you are using virtual hosts) before .htaccess even comes into it. ServerAlias is the directive to use, probably within a VirtualHost container as follows:
[pre]<VirtualHost *>
ServerName www.example.com
[b]ServerAlias *.example.com[/b]
</VirtualHost>[/pre] Once that's all working a request for [anything.example.com...] should return a 404 from your server. Finally, to redirect everything to your www index page you could use a .htaccess something like:
RewriteCond %{REMOTE_HOST} ^[^www]\..*$
RewriteRule ^.*$ http://www.example.com/ [R=302]
[edited by: jdMorgan at 10:24 pm (utc) on Sep. 2, 2005]
[edit reason] [ code ] formatting to fix word-wrapping. [/edit]