views:

274

answers:

2

You own thecheesecakefactory.com and your site lives there. You know that many of your visitors will simply type cheesecakefactory.com into their browser, so you purchase that domain as well.

What is the cleanest way of handling the redirection. I know GoDaddy offers a "domain forwarding" service but I am not sure if this is the "proper" way of handling it, and I don't necessarily like the idea of GoDaddy handling my DNS.

My other option would be sending the domain to my DNS servers and possibly my actual server. Is it possible to do this without setting up a new vhost and a 301 redirect on my server (using DNS only)? If not, how does the GoDaddy forwarding service work?

Update: Solution Below

This is not possible with a CNAME record only (see the chosen answer), it needs to be done on the server level. I ended up implementing a catch-all vhost on my server and pointing the new domain to my server with a simple A record. Here is what I used for a vhost:

<VirtualHost *:80>

    # Catch all

    DocumentRoot /var/www
    ServerName cheesecakefactory.com
    ServerAlias cheesecakefactory.com www.cheesecakefactory.com

    # Re-direct

    RewriteEngine On
    RewriteRule .* http://thecheesecakefactory.com%{REQUEST_URI} [R=301]

</VirtualHost>
+3  A: 

You use a CNAME record. How you set that up varies depending on what you're using for DNS.

EDIT: If you want to use the webserver to accomplish this (as in the other answer) I'd still recommend against using mod_rewrite. mod_alias is much simpler to setup and use, and more clearly expresses your intent. You'd put this in your .htaccess file:

redirect 301 http://thenameyouwant.com
Billy ONeal
Thanks Billy! I am using DNS Made Easy, so I will just point the domain there and setup a CNAME record. Do I even need an A record?
m1755
@m1755: You still need an A record for the target domain name. But you don't need an A record for the name you CNAME'd
Billy ONeal
I already have an A record setup for the target domain, so I should be all set right? Would you mind posting exactly how the CNAME should be setup?
m1755
Shouldn't it be `redirect 301 / http://thenameyouwant.com`?
Matthew Flaschen
m1755
@m1755, GoDaddy's forwarding should do the trick, looks like they even allow permanent forwarding (which you will want). Also avoid their masking, you just want a plain permanent forward (also known as a 301 redirect). If you have access to the server and it's apache, either mod_alias or mod_rewrite are easy to use. If it's IIS then you need to install an ISAPI module and it's more sys-adminy.
vfilby
Thanks vfilby! How do you think GoDaddy is handling it? Are they actually setting up on the fly vhosts and using a 301?
m1755
You don't actually need a vhost for each domain, one domain (or vhost) can respond to many domain names. They likely have a server that handles all forwards, they then receive the HTTP request and perform a redirect (or possibly a rewrite + other magic for the masking), that goes back the the client and it re-requests the page from teh redirected domain, yours. It is a more complicated version of what Bill and I have described.
vfilby
m1755
Why would you be using DnsMadeEasy in conjunction with other GoDaddy services? Wouldn't it make your life easier to consolidate to just with GoDaddy? Most registrars provide some sort of forwarding service, who did you register your domain(s) with? Hosting providers sometimes also handle this who is your hosting provider?
vfilby
Yeah, I like to pay as many people as possible :) Registrar => GoDaddy,DNS => DNS Made Easy,Host => Linode VPS.I am probably going to just throw a catchall vhost in my apache config and forget about it. Was hoping I could do it on the DNS level, but it apparently can't be done.
m1755
Chose the other answer because it doesn't seem to be possible with CNAME only (at least with DNS Made Easy). I ended up using a different rewrite rule and it is working.
m1755
@m1755: No problem choosing the other answer if it worked for you. Though I still think you should use `mod_alias` instead of `mod_rewrite` for this application.
Billy ONeal
+2  A: 

You can not handle this in DNS alone

The redirection has to be handled by the HTTP response. So you will need to configure both DNS and your webserver.

You can set up domain alias's (as in Bill's answer) using CNAMES, but that just means both urls will point to the same server. Both urls will serve up the same content. For SEO reasons this is bad, duplicate content adds to your sites spammy factor.

The proper way to handle this is to setup the CNAME alias so that both urls point to the same server. Once you have that use URL rewriting to ensure all the content is served from the same domain consistently.

To do that use Url rewriting. see apache mod_rewrite or Helicon IIS Rewrite.

RewriteCond %{HTTP_HOST} !^www\.domain\.com 
RewriteRule ^(.*)$ [domain.com...] [R=permanent,L] 
vfilby
The OP is explicitly asking for a solution that A. updates the user's URL and B. is based on DNS. That solution accomplishes neither.
Billy ONeal
Billy, mod_rewrite can optionally send redirects of any type (http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#redirect).
Matthew Flaschen
@Matthew Flaschen: 1. This answer does *not* do that, and 2. that still doesn't solve B. EDIT: Answer was edited and now accomplishes A/1
Billy ONeal
Note that mod_rewrite is overkill here. mod_alias can accomplish this with fewer configuration headaches.
Billy ONeal
Thanks guys! I would prefer not to bother setting up a vhost + 301 for this if possible. I made that more clear in the original post by bolding the *without*. I still appreciate the help.
m1755
@Billy, Same idea just varying levels of flexibility, welcome to the party.
vfilby
@m1755, you don't need another vhost, point both domain names at the smae host (for either solution). AFAIK there is no DNS only solution.
vfilby
According to Billy (above) the CNAME record should accomplish the same thing. Is this incorrect? If no, how is GoDaddy doing it? Are they using vhosts?
m1755
@M1755, CNAMES do not change the url, AFAIK they can not. DNS servers only return the ip address, they do not handling forwarding. Forwarding is handle by the browser as two separate requests. CNAMES are just an alias. If you setup an A record for yoursite.com. You could setup a CNAME for ftp.yoursite.com, redirection here would make no sense.
vfilby
Thanks again! I chose this answer because it is partly how I ended up resolving it, and as a far as I know, it isn't possible with a CNAME only. It seems it might be possible if you have no other records for the domain.
m1755