Forum Moderators: phranque

Message Too Old, No Replies

catch all subdomains

catch all subdomains redirect to main domain.com

         

bluetoothache

3:47 pm on Jun 1, 2005 (gmt 0)

10+ Year Member



i tried posting on this old thread
[webmasterworld.com...]
but its not allowed so am opening a new one.

i failed to implement the solution on the old thread, i do hope someone can clarify some issues.

i simply want the ff.

For instance
[subdomain1.example.com...] I want redirected to http://www.example.com

[subdomain1.example.com...] I want redirected to http://www.example.com

[subdomain2.example.com...] I want redirected to http://www.example.com

[allsubdomains.example.com...] I want redirected to http://www.example.com

and i am also using DNSMADEEASY for my dns settings.

thank you in advance.

jdMorgan

4:27 pm on Jun 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In this particular case:
> http://subdomain1.example.com/widgets.html I want redirected to http://www.example.com
do you really want to "lose" the name of the page requested by the client, and just redirect to the index page?

If so, then the following code will do that.


RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule .* http://www.example.com/ [R=301,L]

Also, you did not specify what you wanted to do if the request was for
http://example.com/ or http://example.com/widgets.html -- i.e no subdomain. The code above will redirect these requests, too.

Jim

bluetoothache

4:45 pm on Jun 1, 2005 (gmt 0)

10+ Year Member



hi jdmorgan,

thank you the reply.

on this issue:

In this particular case:
> [subdomain1.example.com...] I want redirected to http://www.example.com
do you really want to "lose" the name of the page requested by the client, and just redirect to the index page?

yes, it would be too cumbersome to manually recreate/edit every old page & subdomain.

w regards to this,

Also, you did not specify what you wanted to do if the request was for
http://example.com/ or http://example.com/widgets.html -- i.e no subdomain. The code above will redirect these requests, too.

the request for this http://example.com/ should go to http://www.example.com

i tried the code you gave but the subdomains still doesnt redirect to the domain.com

i should take note that my domain nameserver is using dnsmadeeasy.com nameservers, i usually add a cname to every subdomain i need to add on the dnsmadeeasy control panel to support any subdomain changes on the cpanel.

thank you.

jdMorgan

5:05 pm on Jun 1, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First, flush your browser cache before testing *any* change to httpd.conf or .htaccess. Otherwise, your request may be served from your local cache, and never reach your server. If the request is not sent to your server, then your configuration changes can have no effect.

Next, be sure that mod_rewrite is working. You may want to write a simple redirect, such as redirecting a non-existent URL to your home page, to be sure that mod_rewrite is properly configured and functioning.

Dump all the "domain forwarding" and simply define additional A records in DNS for all of your domains, pointing them to the IP address of your server. If a domain is "forwarded" by using a redirect of any kind, then all information about the originally-requested domain will be lost, and mod_rewrite won't have any information to act upon.

Lastly, support for control panels of any kind will be necessarily limted here, because everybody ends up using different combinations of site management software, so the number of people who can answer question about these is going to be limited. Control panels make things 'easy' at the cost of greatly-reduced flexibility, and I won't use them unless absolutely necessary. A bit of server configuration knowledge and a few custom scripts can eliminate the need for them completely.

Jim