2 sites, www and without www, different behaviors

I have 2 sites hosted, but they behave in diferent ways with "www" and without "www":

"http://mainsite.com" gives "It Works!"

"www.mainsite.com" works correctly.

"http://secondary.com" works correctly

"www.secondary.com" gives "It Works!"

"mainsite.com" is also my hostname, maybe it´s something to do with that…

I´m running Ubuntu and Apache.

Thanks for any help.

4 Replies

Yes, lets all play twenty questions because you want to hide YOUR PUBLIC WEBSITES.

@vonskippy:

…you want to hide YOUR PUBLIC WEBSITES.

The names seemed chosen to more clearly illustrate the problem rather than hide anything.

James

What webserver are you using?

If Apache, how did you configure ServerName in the VirtualHost sections?

To treat both as distinct websites out of the same instance, set one to be the servername and then alias the other:

 <virtualhost *:80="">ServerName www.mainsite.com
    ServerAlias mainsite.com
   ...rest of the config...</virtualhost> 

You may want one URL to be the official name though (e.g. http://www.mainsite.com with mainsite.com being a redirect to the other)

Set up the official site in one host and create another to do the redirects.

 <virtualhost *:80="">ServerName http://www.mainsite.com
    ...rest of the config...</virtualhost> 

 <virtualhost *:80="">ServerName mainsite.com
    Redirect permanent / http://www.mainsite.com/</virtualhost> 

Duplicate these two hosts for secondary.com.

@zunzun:

The names seemed chosen to more clearly illustrate the problem rather than hide anything.

There are sooooo many things that depend on the details for everything to work - using generic names removes all of those details from the troubleshooting process.

Personally, I have better things to do then second guess whats wrong, when if all the details were given, the answer would most likely be quick to find and obvious.

Websites (unless they require some type of authenticion) are PUBLIC by nature. So hiding them from the people on this forum (a very very very very tiny fraction of the Internet in general) is not only paranoid to the extreme, but counter productive to getting their problem solved.

But feel free to waste your time ZunZun playing twenty questions - whatever floats your boat, et al.

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