Forum Moderators: phranque

Message Too Old, No Replies

www and no-www please help

         

defessler

6:58 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



I am trying to set up my server to have www.example.com be the same as example.com. I want to make it so that if they type in either example.com or www.example.com it will always recognize it as just example.com.

Do I need to make www a subdomain?

Right now I have the virtual server set up like this.
ServerName example.com
ServerAlias 63.x.x.x www.example.com

coopster

8:12 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, defessler.

Yes and no. What you have there will always use that vhost container when a request comes in for any of the three hosts. However, the proper configuration would be more along the lines of

<VirtualHost 63.x.x.x:80> 
ServerName www.example.com:80
RedirectMatch permanent (.*) http://example.com$1
</VirtualHost>
<VirtualHost 63.x.x.x:80>
ServerName example.com:80
# rest of your directives here
</VirtualHost>

The reason for this is that now you won't be using duplicate content on two different subdomains. This is important for proper search engine indexing.

If you don't have access to your httpd.conf you can get the same effect using mod_rewrite. Their has been plenty of discussion in regards to the "how-to" do so in the Apache Forum here so a quick search should get you started.

defessler

8:52 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



Alright, but do I need to make two virtual servers like that, is there a more condensed way? I have full access to my server.

Also, I am trying to set up multiple domains and make it so that they access phpMyAdmin through sql.expample.com. All domains lead to the same phpmyadmin, but with there respective domain names they have.

For example:
sql.example1.com
sql.example2.com
sql.example3.com

Will all lead to the same phpmyadmin folder. Right now I have those all using serveralias to accomplish and have them set up in bind.

coopster

9:47 pm on Apr 11, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Condensed in this case will be less efficient. With this type of setup your server will only have to redirect if the user is typing in www.example.com in their browser. If you use a single VirtualHost container your server will not only have to locate the correct VirtualHost container first (as it does in both cases being discussed here), but next it will need to analyze every single request to your server once again to determine whether or not it requires redirection. This is the mod_rewrite route. It happens quite quickly but why put your server through the extra effort if it is unnecessary?

As far as your second question here, are you saying that you have the same ServerAlias entry in more than one VirtualHost container?

defessler

10:09 pm on Apr 11, 2008 (gmt 0)

10+ Year Member



Alright I understand that.
Here is currently how I have things set up in both cases.

<VirtualHost 63.x.x.x:80>
ServerName www.example.com:80
RedirectMatch permanent (.*) http://example.net$1
</VirtualHost>
<VirtualHost 63.x.x.x:80>
ServerName example.com:80
DocumentRoot /var/www/html
</VirtualHost>

<VirtualHost 63.x.x.x>
DocumentRoot /home/phpMyAdmin
ServerName sql.example.com
ServerAlias 63.x.x.x sql.example1.com
ServerAlias 63.x.x.x sql.example2.com
</VirtualHost>

As a side note, I have am new to a lot of this. This is actually my first adventure into web servers. I have all this running on a centos4.6 server with a webmin control panel, bind, mysql, and apache.

Also, while most people can can do www.example.com and it will redirect them properly to example.com but some people they can not use the www part or else it gives server not found. Is this something that takes a little bit of time before it's 100% or did I set something up wrong with my named server.

jdMorgan

2:22 am on Apr 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, while most people can can do www.example.com and it will redirect them properly to example.com but some people they can not use the www part or else it gives server not found. Is this something that takes a little bit of time before it's 100% or did I set something up wrong with my named server.

That's likely a DNS propagation delay issue, and should resolve over time. In most cases, DNS updates for modern ISPs take only a few hours. If the ISP is in an economically-disadvantaged country and is using old equipment or has it misconfigured, it might take many days to update. I've also seen some corporate networks take up to a week to update... not sure why.

Jim

defessler

6:12 am on Apr 12, 2008 (gmt 0)

10+ Year Member



Alright, that's fine. The only other question I have is if the way I have the server alias set up is an effective way to do it.

coopster

9:36 pm on Apr 12, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you need to specify multiple IP addresses, I would put that in the <VirtualHost> directive, otherwise lose them. Also, you can specify wildcards in the ServerAlias [httpd.apache.org] so something like this may work for you:

<VirtualHost 63.x.x.x> 
DocumentRoot /home/phpMyAdmin
ServerName sql.example.com
ServerAlias sql.example?.com
</VirtualHost>

The only thing I am uncertain about is the application, phpMyAdmin, as I don't use it enough to know it's detail operations. If I were doing something like this and it required login or something I would be very sure of how the application works and who can manage what.

defessler

1:59 am on Apr 14, 2008 (gmt 0)

10+ Year Member



Oh yes, of course. I can create accounts with restrictions so they can only access the databases they need to.