1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Aliasing Setup

Discussion in 'Mac OS X Server, Xserve, and Networking' started by keith1995, May 18, 2009.

  1. macrumors newbie

    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: 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?
  2. macrumors 6502

    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.
  3. macrumors newbie

    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?
  4. macrumors G4

    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.

Share This Page