How to Redirect a non-www. URL to a www. URL

In the world of web development and search engine optimization (SEO), properly managing your website's URLs is crucial. One common practice is to ensure consistency between the "www" and "non-www" versions of your domain. This guide will walk you through the process of redirecting a non-www URL (e.g., https://example.com) to its www counterpart (e.g., https://www.example.com).

In this article, you'll find: 

  1. What the "www." part of the URL is used for
  2. Benefits of redirecting traffic to the "www." version of your site
  3. Ways to implement the redirect
  4. How to implement the redirect using redirect.pizza
  5. Conclusion

What Is The "www." Part of the URL used for? 

The "www." part of a URL, known as the "www" subdomain, serves several purposes:

  1. Historical convention: The use of "www" originated in the early days of the World Wide Web as a way to distinguish web servers from other types of servers (like FTP or mail servers) on the same domain.
  2. Subdomain identification: Technically, "www" is a subdomain of the main domain. For example, in "www.example.com", "www" is a subdomain of "example.com".
  3. Server differentiation: Some websites use "www" to differentiate between different servers or to distribute traffic across multiple servers (e.g., www1, www2, www8).
  4. Consistency and user experience: Many websites maintain both "www" and non-"www" versions for consistency and to meet user expectations, as some users habitually type "www" before domain names.
  5. Cookie management: Using a "www" subdomain can help restrict cookies to that specific subdomain, potentially improving privacy and performance.
  6. SEO considerations: While not strictly necessary, some websites use "www" for search engine optimization purposes, ensuring that search engines treat the "www" and non-"www" versions as the same site.

It's important to note that the use of "www" is not technically required for a website to function. Many modern websites operate without it, using the "naked" domain, or "apex" domain (e.g., https://example.com) as their primary URL. However, it's considered best practice to choose either the "www" or non-"www" version of your website. This means that it's best to redirect one version to another. 

Redirecting to one URL variant offers several benefits:

Ensuring that your website is only accessible via one version of your website, such as via the "www." URL, has a number of benefits. 

  1. Improved SEO performance: search engines only need to crawl one version of your site (the URLs starting with "www.")
  2. Consistent user experience: users will always visit your site via the "www." version of the URL. 
  3. Simplified analytics tracking: all traffic will flow to one version of your site. If you dont redirect all traffic to one version, the same page may get traffic data via two different URLs, making it harder to interpret your website's analytics. 
  4. Prevention of duplicate content issues

Whether you're a seasoned web developer or just starting out, this step-by-step tutorial will provide you with the knowledge and tools needed to successfully set up this important redirect. Let's dive in and explore the various methods to achieve this

Ways to redirect to the "www." URL

You can redirect the naked domain, or apex domain, to the "www." subdomain by implementing a 301 redirect. Why a 301 redirect? It signals a permanent move notice to search engines, therefore telling search engines that the website is only accessible via the "www." URL. There are a number of ways to do this: 

Manually adding a “301 Redirect” comes with inherent risks because you are making changes to the .htaccess file of your domain – something that could go terribly wrong if you are not confident in what you are doing. The .htaccess file controls your site configuration and one misspelling or a missed symbol, and you are looking at a very messy situation!

Adding the following code to the .htaccess file on your Apache server should create a 301 redirect:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

Just replace the “example.com” in the code above with your URL.

Setting up a 301 redirect manually varies depending on the server setup, and each web server handles this process differently. It is also worth noting that this process is further complicated by the need for an SSL certificate for the non-www domain URL as well, unless a SAN SSL certificate is set up. All of these moving parts make it much more likely that something will go awry, so it is always best to follow up with your host directly or use a risk-free 301 redirect instead.  

Some DNS providers allow you to set up a redirect via them. For example:

Namecheap 

With Namecheap, you can easily redirect subdomains by using the ‘Advanced DNS’ tab. Here, you can add URL Redirect Records or create subdomains that can be forwarded to different locations, such as URLs or IP addresses. Learn more about how to create a redirect in Namecheap

AWS Route 53 

With AWS Route 53, you can redirect to the "www." subdomain by setting up special DNS records, like A or CNAME records. The records serve as instructions that ensure the traffic is correctly directed to the intended destination. Learn more about it here

Cloudflare 

Like AWS Route 53, Cloudflare allows subdomain redirection by creating DNS records, such as A or CNAME records. Check out their how-to guide to learn more. 

GoDaddy 

GoDaddy supports subdomain redirection through its DNS management interface. You can use the interface to create forwarding rules for your subdomains.

A subdomain redirect can also be set up via your content management system. Below, we’ll discuss how to do this in some of the frequently used CMS systems. (Keep in mind, though, that your CMS needs to be linked to your subdomain in order to be able to do this.)

WordPress

In WordPress, there are a variety of ways to redirect a subdomain. For instance, there are plenty of redirection plugins available to install. WordPress also enables you to connect subdomains to either a separate WordPress.com site, an external site, or a specific non-homepage of your domain. 

Webflow 

With Webflow you can set up a subdomain redirect within the project settings. Webflow offers a step-by-step guide to get you started. 

Wix 

Wix provides a URL Redirect Manager found within the site's dashboard, under the tab for SEO Tools. Here, you can create new redirects by specifying the old and new URLs. Learn more about how to connect a subdomain to an external source in Wix.

Dedicated domain redirect services, such as redirect.pizza, allow you to effortlessly create, manage, and edit your redirects. They provide a lot of benefits, such as ease of use, reliability, performance, scalability, and centralized management of your redirects. 

Benefits of using redirect.pizza for your subdomain redirects

It seems like each method has its drawbacks.  But there is a way to go around these limitations. redirect.pizza can help! We’ve listed all of the benefits of using redirect.pizza right below.

How to redirect a non-www URL to a www. URL

  1. 1

    Step 1: Create a redirect.pizza account

    Create a redirect.pizza account. Once you've created the free account, you can access our redirect features. 

    registration page redirect.pizza

  2. 2

    Step 2: Create redirect

    After signing up, click on "create a redirect" to get started. In the create a redirect window, enter the source URL (such as the non-www URL) and the destination URL (the URL including "www."). Learn more in our getting started guide

    Create redirect

  3. 3

    Step 3: Adjust DNS settings

    The required DNS change pops up. Go to your domain registrar to make this DNS change for the A record. Alternatively, you can use our Automatic DNS feature to make these changes. It may take up to 24 hours for the DNS changes to propagate. 

  4. 4

    Step 4: Test your redirect and keep track of your analytics

    Type your (old) source URL in the address bar of your browser and click "enter". Are you redirected to the destination URL? Then the redirect is working! You can keep track of your redirect using the Redirect Analytics window. Are you experiencing issues? Check out our redirect troubleshooting guide

Conclusion

Although mostly considered a cosmetic tradition, there are some advantages to using the “www” prepend for your domain. If your site does not currently direct surfers to a “www” URL, redirection is as easy as adding the original URL and the redirection URL to a URL redirect tool like redirect.pizza!