-1

I'm a web developer on a software house, which develops websites for clients. The websites are hosted by third party, so we don't have full control over it.

One of our clients one day asks us, why they can access their website if they write to the address, say: www.example.com/, but they can't connect if the address is, say: example.com/ ? They need that the website can be accessed normally with or without the www. When accessed without the www, it's not returning 404 server not found. The browser can find the server of the website, but instead returning the website's own 404 resource not found error page. That means the url without www is pointing to a nonexistent resource within the website, but the website itself is found. I still can't understand why www.example.com/ point to different resources than example.com/. I still don't know where the example.com/ points to.

The server is using apache-tomcat, and the web pages are served using servlet and Enfinity framework.

I initially suspect this has something to do with DNS. But now I'm not sure so much. Can you point me to the direction of which may go wrong? Thank you very much.

Note: I don't know if this question is appropriate to be posted on the Server Fault. If it's off topic, please kindly transfer it to appropriate forum.

2 Answers 2

2

This is a DNS question, but given how browsers work, it is also partially a browser / web server question.

You can determine which is the primary issue using the commands:

nslookup example.com
nslookup www.example.com

If the output is the same, you should look to the web server. If they are different, you should talk to the people in charge of your DNS.

DNS

From the perspective of DNS, example.com is a DNS name, just as www.example.com is a DNS name. example.com is also a domain, as it contains other DNS names (e.g. www.example.com). example.com and www.example.com can both have "A records" (associated IP addresses), and those IP addresses may even be different from each other. As an example:

example.com -> 1.1.1.1 
www.example.com -> 2.2.2.2

The 'www' portion of the hostname comes from the protocol (HTTP, used for World Wide Web (WWW or www) service). You might also have ftp.example.com, mail or smtp.example.com, etc. Each would logically be expected to provide service for the protocol(s) being referenced, and each could have a different IP address.

These days, HTTP is pretty common, so often domain administrators will cause example.com to point to the IP address of their web server.

Web server

The other part that matters is the web server. It is possible for the web server to direct web browsers differently based on the hostname the browser was given. This is the server name or Host header provided by the web browser. How this is done or fixed is a configuration question that depends on which web server you use, and might be worth a different question.

3
  • I just tried the nslookup command, and both return the same address. The only difference is that when I run the nslookup for www.example.com, I get "extended" info under the ip address: "Alias www.example.com". Whereas nslookup example.com doesn't have the "extended" info. I don't know if it means anything or not. So, you think this is more of a server (apache / tomcat) configuration problem, than a html / JSP / servlet coding problem? Mar 13, 2014 at 4:31
  • It seems to be based on what you are reporting. Apache can discriminate based on the hostname using the ServerName directive if I recall correctly. Probably in other ways as well. I know nothing of Tomcat. Mar 13, 2014 at 4:35
  • Okay, I will look into the matter further. Thank you very much. Mar 13, 2014 at 4:39
0

Assuming that both www.example.com and example.com go to the same IP address and the web server serving that site has bindings that are configured to send HTTP requests with either header to the same place, there is no difference.

Let's say you own the domain example.com.
You can create a number of hosts (ie subdomains, ie records)
An example would be helloworld.example.com. It's just a record.
The same goes for www. It is just a record that is mapped to a particular IP address.

Some web admins decide that they do not want a www record at all and consequently when you browse to their site www.site.com, you do not find anything.

I suppose we still use it because it is legacy.

3
  • Thank you for the answer. So, if the server "answers" the client's browser "query", even though the "answer" is just a custom 404 error page, does that mean the server configuration is already correct and it serve both domain records? Mar 13, 2014 at 4:37
  • Nope, sounds like the web server is configured not to serve anything on www.example.com:80 and is instead showing you a 404. Mar 13, 2014 at 4:38
  • Oh I see. Okay I will try to ask the web hosting about the server configuration. Thanks! Mar 13, 2014 at 4:40

Not the answer you're looking for? Browse other questions tagged .