domain with www and without www

I have recently moved my VPS to linode and I am having an issue that has been bothering me for days. I only have a very basic knowledge of this type of thing so I am not sure what else to try at this point.

The problem:

www.mydomain.com <–- goes to correct virtualhost

mydomain.com <--- goes to default virtualhost which is not correct

I have a fresh Debian 6 vps with very basic stuff on it right now( LAMP ), I am also using a sub domain *.mydomain.com which works perfectly fine.

My default virtualhost has not been modified at all and is the default, mydomain.com virtualhost file is created exactly as instructed in the tutorial http://library.linode.com/lamp-guides/debian-6-squeeze

I have done a lot of searching over the past few days that I have been trying to figure this out including reading every single topic I could find on this forum about it. I have attempted every single possible solution I could find to the best of my abilities with no success.

I even contacted my domain provider to have them verify my A records and other records to make sure I didn't mess anything up in the process and they assured me that everything is perfectly fine.

So the conclusion is that I am obviously missing something but I am just not sure what and I would appreciate any help on this.

11 Replies

Could you paste your VirtualHost files and the output of apachectl -S please?

It sounds like you've provided "ServerName www.mydomain.com" and have no "ServerAlias mydomain.com" or vise versa.

Since I can't see your configuration, I can only guess, but it's possible that you have two separate vhosts configured. If you want www.domain.com to go to the same place as domain.com, they should be in the same vhost.

Apache allows you to put a "ServerAlias" in the vhost, putting subdomains and other domains in the ServerAlias will tell apache that any connections to these "aliases" go to the same place as the main domain that you want have the vhost for.

If that's not the issue, we need to have your vhost config files. Depending on what the actual issue is, we might need the main apache configuration file, though I doubt this will be the issue since apache already seems to be working.

As requested:

–-------------

VirtualHost configuration:

wildcard NameVirtualHosts and default servers:

*:80 is a NameVirtualHost

default server mydomain.com (/etc/apache2/sites-enabled/000-default:1)

port 80 namevhost mydomain.com (/etc/apache2/sites-enabled/000-default:1)

port 80 namevhost mydomain.com (/etc/apache2/sites-enabled/mydomain.com:1)

Syntax OK

 <virtualhost *:80="">ServerAdmin webmaster@mydomain.com
        ServerName mydomain.com
        ServerAlias www.mydomain.com
        DocumentRoot /srv/www/mydomain.com/public_html/
        ErrorLog /srv/www/mydomain.com/logs/error.log
        CustomLog /srv/www/mydomain.com/logs/access.log combined
        ErrorDocument 404 /missing.php</virtualhost> 

Have you got the "alias" apache module loaded?

apache2ctl -t -D DUMP_MODULES

Loaded Modules:

core_module (static)

logconfigmodule (static)

logio_module (static)

mpmpreforkmodule (static)

http_module (static)

so_module (static)

alias_module (shared)

authbasicmodule (shared)

authnfilemodule (shared)

authzdefaultmodule (shared)

authzgroupfilemodule (shared)

authzhostmodule (shared)

authzusermodule (shared)

autoindex_module (shared)

cgi_module (shared)

deflate_module (shared)

dir_module (shared)

env_module (shared)

mime_module (shared)

negotiation_module (shared)

php5_module (shared)

reqtimeout_module (shared)

rewrite_module (shared)

setenvif_module (shared)

status_module (shared)

Syntax OK

Does the output of "hostname -f" say "mydomain.com"? If so, try changing your system hostname to something specific, like "bob.mydomain.com".

full qualified domain name is not the same and just to be sure I changed it to something else and still no luck.

Do you have (domain.com) and (www.domain.com) in your DNS A/AAAA record?

linode DNS manager a/aaaa record should have one blank hostname entry and another for www Other than that the ServerAlias Should work with default install of apache on debian squeeze. copy both and replace ip address with ipv6 if you use that also.

evilyummycandy, your problem would be because of the default vhost that you have has the same ServerName/ServerAlias values, which is going to cause problems. Please paste the file "/etc/apache2/sites-available/default" to confirm this.

What Apache is currently doing is using the config in "/etc/apache2/sites-available/default" to serve the domain "mydomain.com".

If you don't need this default vhost (which from the looks of it, you don't) then you can simply do the following:

a2dissite default && unlink /etc/apache2/sites-available/default

The default vhost is simply the one that Apache comes across first in it's configuration, you don't need one called "default". This is just a Debian convention.

I just got back from work and I checked the www and without www and it works o_O.

I have done nothing else since my last attempt and now I am scared to mess with it because I will probably break it, for now I think it is best to leave it as is while it is working because I still have a ton of other things that I need to do to this VPS to get it up and running.

Even thought I have no idea what was done that magically fixed it( yes it is magic ) I would still like to say thanks to everyone who assisted me.

@AlecC: I did not edit my default and it is still up and running.

Possibly a delay in your ISPs DNS. Just because your DNS records are updated doesn't mean everybody else's will be. Since you switched from another hosting company (and thus your server IP changed), it will take time for ISPs around the world to update their DNS to the new server. Different ISPs update at different intervals – some update more frequently than others. Normally it takes up to 24 hours for everybody's DNS records to update, though doing a google search a few minutes ago, I saw a couple reports of it taking a maximum 72 hours, though it seems rare that would would actually take that long.

(edited to correct myself)

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct