Forum Moderators: phranque

Message Too Old, No Replies

Non-existent subdomains showing mirror of home page!

         

vishalrao

6:53 am on Nov 23, 2004 (gmt 0)

10+ Year Member



Hello,

I have my domain on dedicated IP. When I try to visit subdomains of my site that do not exist, it shows the mirror of my home page. When I tried to contact the support staff, they told me it happens because my site is on dedicated IP.

For my other domains that are on shared IP, non-existent subdomains show me some control panel page instead of 404 error.

How can I solve this?

Thanks,

Vishal P. Rao

jdMorgan

4:27 pm on Nov 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Vishal,

Welcome to WebmasterWorld!

There are a few things you can try if you want to get rid of the "duplicate domains."

1) Modify your DNS records, and disable "wild-card" DNS. This will prevent undefined subdomains from resolving to your IP address, and requests to those subdomains will return a DNS error.

2) Add some code to .htaccess in your Web root directory to redirect all undefined subdomains to your main domain.

3) Modify the code in step 2 to define a few subdomains for useful purposes. For example, you can create test.example.com as a subdomain of your site at www.example.com. You can use this domain to test new pages and code for your site on the "live" server.

Your DNS record probably looks something like this now:

ftp.example.com. IN A 192.168.0.1 
smtp.example.com. IN A 192.168.0.1
*.example.com. IN A 192.168.0.1

or possibly even just:

*.example.com.  IN A 192.168.0.1

If you change it to read:

ftp.example.com. IN A 192.168.0.1 
smtp.example.com. IN A 192.168.0.1
www.example.com. IN A 192.168.0.1

Then only the "www.example.com" domain will resolve to your server for HTTP connections. (Be sure to make a copy of your existing DNS records before modifying them!)

Alternatively, you can put some mod_rewrite code into your .htaccess file to permanently redirect the "extra" subdomains to your main domain:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

The code above will only work with HTTP/1.1 clients; HTTP/1.0 clients do not provide the Hostname header that this code depends on. All the major search engines use HTTP/1.1, although some of them "claim" to be using HTTP/1.0 -- therefore I use the check for the blank Hostname value in the code, instead of checking the protocol declaration. Also, some hosting services may not support the use of mod_rewrite. For HTTP/1.0 clients, you'll have to use the DNS solution. There is no mod_rewrite solution that will fix that.

The above is a quick overview, and you may run into problems I have not described here due to hosting restrictions. But these methods will work for many hosting setups, so you can try them and then decide on a solution that will work for you.

Jim