Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

keith1995

macrumors newbie
Original poster
May 18, 2009
3
0
I'm having some problems setting up a simple alias for a website.

We have created a new site via server admin with settings such as this:

domain name: http://www.domain.com
host decription: domain.com
alias: domain.com

Our DNS looks like this:

@ A (Host) xxx.xxx.xxx.xx
www A (Host) xxx.xxx.xxx.xx

What we are trying to accomplish is that if you goto http://domain.com it should alias to http://www.domain.com however it is continuing to serve the site http://domain.com and the www only displays if you go directly to http://www.domain.com.

What am I doing wrong?
 

SHIFTLife

macrumors 6502
Jul 24, 2008
293
0
You can do this without using DNS to make it happen. I force the removal of www. on my website using .htaccess. In the root of your web server directory, there may be a hidden file called .htaccess. If it's not there, you can create it.

Add the following lines to the .htaccess file to force the addition of www.:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.your_domain.com$
RewriteRule ^(.*)$ http://www.your_domain.com/$1 [R=301]

Replace both instances of your_domain with your domain name. Also, if you're not using .com as your TLD, make sure you change the TLD from .com to whatever you're using.

EDIT: As an added benefit, this will force any search engines to use the www. version of your site to avoid duplicate content. This is beneficial for any "public" website.
 

keith1995

macrumors newbie
Original poster
May 18, 2009
3
0
Thanks for the reply.

We'd like to use the alias feature in Server Admin and not rely on .htaccess for the www redirect if possible.

What is odd is that the non-www aliasing is working fine for a few other sites we have setup already but not for a few we just setup yesterday. They appear to be using the same exact settings so I'm guessing something is amiss when it comes to DNS?
 

ChrisA

macrumors G5
Jan 5, 2006
12,578
1,694
Redondo Beach, California
I think the way it works it that even if DNS point 100 different domain names to the same IP address Apache still "sees" the URL the browser sent. The term to google for is "virtual host"
Or just read link below. I think what you want is two hosts one with and one without the WWW. Both using the same IP address and going to the same document directory.
http://httpd.apache.org/docs/1.3/vhosts/
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.