Page 1 of 1

Subdomain/GoDaddy

PostPosted: 03. December 2011 09:02
by Koala
Hi,

I want to create two subdomains for my domain. I got my domain at GoDaddy, lets say example.com and I created first.example.com and second.example.com as subdomains.

Now, this is the part I'm not sure. I went to Zone File Editor and added 2 CNAME(Alias).

1.
Host: first
points to: @

2.
Host: second
points to: @

I Also tried that on the A(Host).

Now, on XAMPP I did configurate the httpd-vhosts.conf:
Code: Select all
<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    DocumentRoot c:/xampp/htdocs
    ServerName example.com
    ServerAlias www.example.com
</VirtualHost> 

<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    DocumentRoot c:/xampp/htdocs/first
    ServerName first.example.com
    ServerAlias www.first.example.com
</VirtualHost> 

<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    DocumentRoot c:/xampp/htdocs/second
    ServerName second.example.com
    ServerAlias www.second.example.com
</VirtualHost>


But the problem is that I always get example.com. Doesn't matter if I put first.example.com or second.example.com. I always reach example.com!

Any one know what I'm doing wrong?
Much appreciated.

Re: Subdomain/GoDaddy

PostPosted: 03. December 2011 09:23
by Sharley
See if these search results from Google help with the zone file edits at GoDaddy.


Before we start I first need to know what you see when you type http://localhost in your browser?

Do you have all your web site files for example.com in the htdocs folder?

Did you delete or rename the default XAMPP index.html and index.php that was already in the htdocs folder?


You're seeing only the first vhost which is the default vhost in your current settings.

Open a command prompt in the \xampp\apache\bin folder and type
Code: Select all
apache.exe -S
and paste the result here please - you can use the edit menu found by clicking on the small icon top left of the console window.

I will make a few suggestions when you have provided the above requested information.
Thanks.

Re: Subdomain/GoDaddy

PostPosted: 03. December 2011 09:43
by Koala
Thanks for the prompt reply,

Sharley wrote:Before we start I first need to know what you see when you type http://localhost in your browser?

I see my default site: example.com

Do you have all your web site files for example.com in the htdocs folder?

Yes. example.com files are in htdocs folder.

Did you delete or rename the default XAMPP index.html and index.php that was already in the htdocs folder?

I deleted them. I just kept the XAMPP folder inside htdocs(I read on the FAQ it was OK).

Open a command prompt in the \xampp\apache\bin folder and type
Code: Select all
apache.exe -S
and paste the result here please - you can use the edit menu found by clicking on the small icon top left of the console window.

Code: Select all
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Koala>cd..

C:\Documents and Settings>cd..

C:\>cd xampp

C:\xampp>cd apache

C:\xampp\apache>cd bin

C:\xampp\apache\bin>apache.exe -S
[Sat Dec 03 03:38:17 2011] [warn] _default_ VirtualHost overlap on port 80, the
first has precedence
[Sat Dec 03 03:38:17 2011] [warn] _default_ VirtualHost overlap on port 80, the
first has precedence
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80                   example.com (C:/xampp/apache/conf/extra/httpd-vhosts.con
f:27)
*:80                   first.example.com (C:/xampp/apache/conf/extra/httpd-v
hosts.conf:34)
*:80                   second.example.com (C:/xampp/apache/conf/extra/httpd-vhos
ts.conf:41)
_default_:443          localhost (C:/xampp/apache/conf/extra/httpd-ssl.conf:74)
Syntax OK

C:\xampp\apache\bin>


Thanks!

Re: Subdomain/GoDaddy

PostPosted: 03. December 2011 10:08
by Sharley
Now assuming that your domain and sub domains at GoDaddy all correctly point to the IP address of your XAMPP server then using the following slightly edited vhost config may help.

www is also classed as a sub domain in the zone file but not sure if you can use a http://www.sub.domain.com in the vhosts file but this you can experiment with.
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "C:/xampp/htdocs"
    ServerAdmin webmaster@example.com
</VirtualHost>

<VirtualHost *:80>
    ServerName first.example.com
    ServerAlias www.first.example.com
    DocumentRoot "C:/xampp/htdocs/first"
    ServerAdmin webmaster@example.com
</VirtualHost>

<VirtualHost *:80>
    ServerName second.example.com
    ServerAlias www.second.example.com
    DocumentRoot "C:/xampp/htdocs/second"
    ServerAdmin webmaster@example.com
</VirtualHost>
Without the NameVirtualHost line Apache thinks that your vhosts are IP based and so a warning for the overlap.

Don't forget to Save and restart Apache and if Apache can't start check the \xampp\apache\logs\error.log file for clues.

BTW, when using a VirtualHost your web sites don't have to be in the htdocs folder, they can be located anywhere on your PC.

Please let me know how this all pans out and if the Google search results helped with GoDaddy's zone file settings.

Best wishes. :)

Re: Subdomain/GoDaddy

PostPosted: 03. December 2011 16:29
by Koala
Sharley wrote:Now assuming that your domain and sub domains at GoDaddy all correctly point to the IP address of your XAMPP server then using the following slightly edited vhost config may help.

www is also classed as a sub domain in the zone file but not sure if you can use a http://www.sub.domain.com in the vhosts file but this you can experiment with.
Code: Select all
NameVirtualHost *:80

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot "C:/xampp/htdocs"
    ServerAdmin webmaster@example.com
</VirtualHost>

<VirtualHost *:80>
    ServerName first.example.com
    ServerAlias www.first.example.com
    DocumentRoot "C:/xampp/htdocs/first"
    ServerAdmin webmaster@example.com
</VirtualHost>

<VirtualHost *:80>
    ServerName second.example.com
    ServerAlias www.second.example.com
    DocumentRoot "C:/xampp/htdocs/second"
    ServerAdmin webmaster@example.com
</VirtualHost>
Without the NameVirtualHost line Apache thinks that your vhosts are IP based and so a warning for the overlap.

Don't forget to Save and restart Apache and if Apache can't start check the \xampp\apache\logs\error.log file for clues.

BTW, when using a VirtualHost your web sites don't have to be in the htdocs folder, they can be located anywhere on your PC.

Please let me know how this all pans out and if the Google search results helped with GoDaddy's zone file settings.

Best wishes. :)


It worked! Thank you so much!

Though it doesn't work with www. (only the top level domain works) still good. Maybe I should add www vhost for each subdomain? but the ServerAlias shouldn't do the trick?
However, maybe something like this:

Code: Select all
<VirtualHost *:80>
    ServerName www.first.example.com
    ServerAlias first.example.com
    DocumentRoot "C:/xampp/htdocs/first"
    ServerAdmin webmaster@example.com
</VirtualHost>

Re: Subdomain/GoDaddy

PostPosted: 03. December 2011 23:21
by Sharley
You could try that because as I said that www is already classed as a sub domain and may need you to experiment with it to achieve your desired result.

You could also try
Code: Select all
<VirtualHost *:80>
    ServerName first.example.com
    ServerAlias *.first.example.com
    DocumentRoot "C:/xampp/htdocs/first"
    ServerAdmin webmaster@example.com
</VirtualHost>
Or drop the ServerAlias altogether and create separate vhosts
Code: Select all
<VirtualHost *:80>
    ServerName first.example.com
    DocumentRoot "C:/xampp/htdocs/first"
    ServerAdmin webmaster@example.com
</VirtualHost>

<VirtualHost *:80>
    ServerName www.first.example.com
    DocumentRoot "C:/xampp/htdocs/first"
    ServerAdmin webmaster@example.com
</VirtualHost>

The ServerAlias docs:
http://httpd.apache.org/docs/2.2/mod/co ... erveralias

Good luck. :)

Re: Subdomain/GoDaddy

PostPosted: 05. December 2011 07:02
by Koala
First of all, thanks for the help so far.

I tried both ways, but neither way works. www. works with top level domain and I think it should work with the others but it doesn't, doesn't matter if I mention it on the ServerAlias or giving their own vhosts.

If www is a subdomain itself, I'm trying to put together two subdomains, like doing first.second.example.com? So maybe that's why it isn't possible?

Re: Subdomain/GoDaddy

PostPosted: 05. December 2011 07:14
by Sharley
Copy your httpd-vhosts.com file so you can use a copy to reduce the content to just
first.example.com and www.first.example.com
It is often best to create just one or two vhosts and getting those working before adding others one at a time then it is possible to find which is causing the problems.

Then could you paste here once again the command apache -S result so I can see perhaps why this is occurring - this command is very useful for troubleshooting as is the apache error.log file.
Thanks.

Re: Subdomain/GoDaddy

PostPosted: 05. December 2011 07:34
by Sharley
I have just tested using localhost by adding both sub domain names to the Windows HOSTS file and both worked as expected when I edited the httpd-vhost.conf file like so
HOST file
Code: Select all
127.0.0.1 first.example.com
127.0.0.1 www.first.example.com
httpd-vhosts.conf file
Code: Select all
<VirtualHost *:80>
    ServerName first.example.com
    DocumentRoot "C:/xampp/htdocs/first"
    ServerAdmin webmaster@example.com
</VirtualHost>

<VirtualHost *:80>
    ServerName www.first.example.com
    DocumentRoot "C:/xampp/htdocs/first"
    ServerAdmin webmaster@example.com
</VirtualHost>
So it is possible that your Zone file is not correct if you are trying to connect through the Internet.

I also tested this httpd-vhosts.conf file
Code: Select all
<VirtualHost *:80>
    ServerName first.example.com
    ServerAlias *.first.example.com
    DocumentRoot "C:/xampp/htdocs/first"
    ServerAdmin webmaster@example.com
</VirtualHost>
also it worked on my PC using the same HOSTS file entries as the first test.

You can't use the HOSTS file if you are trying to access from the Internet (but is a good way to test your vhosts configurations), that is governed by the domain name zone file - sometimes editing this file can take some time to work it's way through the Internet DNS caches (propagation).

Best wishes. :)