Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain IP address for www and non-www for Canonical URL

Tags:

seo

subdomain

dns

To handle Canonical URL is it best practice to do a 301 redirect or better to have the same IP Address for both www and non www domain?

For example:

Canonical URL/domain wanted is http://example.com

Domain           | A Record ------------------------------------ example.com      | 192.0.2.34 www.example.com  | 192.0.2.34 

I understand people may have a CNAME record for www (alias, given that CNAME is called Canonical Name); unsure if this is best practice compared to using the same IP address.

Or is this better.

Domain           | A Record ------------------------------------ example.com     | 192.0.2.34 *  www.example.com 301 redirect to example.com 
like image 804
Wasabi Developer Avatar asked Oct 24 '13 13:10

Wasabi Developer


People also ask

Which is better for SEO www or non-www?

The short answer to the www vs non-www question is that there is no big difference, no matter which you use. However, if you deep dive a bit, you will realize that www domains have some slight technical benefits that improve a website's performance.

How do I redirect a domain without www to www?

Click on the Redirects icon under the Domains area of your cPanel home page. Select your domain name from the drop down menu on the next line. In the redirects to text box, type in the full URL of your domain, without the www (e.g. http://yourdomain.com). Select the radio button next to Only redirect with www.

What is a domain called without www?

A domain without the "www" is called a "naked domain."

Should you redirect www to non-www?

For example, if you've chosen to use non-www URLs as the canonical type, you should redirect all www URLs to their equivalent URL without the www. Example: A server receives a request for http://www.example.org/whaddup (when the canonical domain is example.org)


1 Answers

The mechanisms you describe (A and CNAME records vs. 301 redirects) are part of two different protocols (DNS and HTTP). A and CNAME records have nothing to do with which site your HTTP server serves for different requests.

Let's look at two different DNS configurations:

Configuration 1 (CNAME record)

Host             | Type  | Data -----------------+-------+------------- example.com      | A     | 192.0.2.34 www.example.com  | CNAME | example.com 
  • nslookup example.com resolves to 192.0.2.34
  • nslookup www.example.com resolves to 192.0.2.34

Configuration 2 (A records)

Host             | Type  | Data -----------------+-------+------------- example.com      | A     | 192.0.2.34 www.example.com  | A     | 192.0.2.34 
  • nslookup example.com resolves to 192.0.2.34
  • nslookup www.example.com resolves to 192.0.2.34

In both cases your canonical domain and your www subdomain resolve to 192.0.2.34. However, the only thing your HTTP server will recognize is that it receives requests for both example.com and www.example.com on the same IP address. But it doesn't know whether you used A or CNAME records for that.

TL;DR

You have to use HTTP 301 redirects to enforce the canonical example.com in HTTP requests. But that has nothing to do with your DNS configuration.

like image 122
PoByBolek Avatar answered Sep 20 '22 11:09

PoByBolek