Forum Moderators: phranque

Message Too Old, No Replies

How to capture wildcard sub-domain traffic?

         

trader

8:46 am on Sep 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have been asking about this for a few yrs at several different forums and no one seems to know the answer, or else they know but do not reply.

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.

dmorison

9:02 am on Sep 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi trader,

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]

trader

3:29 pm on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, working on it now, most appreciated.