4 minutes of reading

Redirecting a domain from www to non-www – how to do it?

Redirecting a domain from www to non-www – how to do it? - photo no. 1

Redirecting a domain from www to non-www – how to do it?

After registering a domain, your website responds to two addresses – one with and one without the www prefix. The difference is cosmetic to the user, but the search engine treats both variants as separate hosts with the same content. However, a single redirect rule is enough to ensure that all traffic and ranking signals are sent to a single address. This article will teach you how to implement it on your server, in your hosting panel, Cloudflare, and CMS, and how to verify that it's working properly.

Why does one page with two addresses lose in search results?

Why does Google see two addresses instead of one?

Google identifies a website by its full hostname. The addresses www.domenaxyz.pl and domenaxyz.pl are considered two different pages with identical content. The effects are visible primarily in the link profile – some sites link to the version with the prefix, others to the shorter one, so the authority is spread across two addresses . The crawler also visits both versions of each subpage, so the crawl budget is doubled.

In this situation, Google documentation recommends manually specifying the canonical version and directing traffic to it. The strongest signal is a 301 redirect , which informs the search engine of a permanent address change and transfers the accumulated power to the target address. Unifying the domain version is about streamlining the signals your site has already developed—not about fighting the algorithm.

Domain with or without www – what influences the choice of version?

Google doesn't favor either option, so the decision depends on technical and image considerations. There are two arguments in favor of the prefix. The first concerns DNS – you can set a CNAME record for the www hostname, which the standard doesn't allow for the root domain . This simplifies using a CDN and moving a site between servers. The second argument is cookie scope. A cookie set on the root domain covers all subdomains, so a website with a separate application subdomain can more easily monitor session data under www.

(The rest of the article can be found below the form)

Fill out the form and schedule a call with an expert

We'll get to know your business and prepare a personalized quote for the optimal marketing mix. Completely free.

The controller of your personal data is Verseo, a limited liability company with its registered office in Poznań, at ul. Węglowa 1/3.

About Verseo

The Company's registered office is located in Poznań. The Company is entered in the Register of Entrepreneurs maintained by the District Court for Poznań – Nowe Miasto and Wilda in Poznań, 8th Commercial Division of the National Court Register, under KRS number: 0000910174, Tax Identification Number (NIP): 7773257986. You can contact us by mail at the address provided above or by email at: ochronadanych@verseo.pl

You have the right to:

  1. access to your data,
  2. rectification of your data,
  3. request deletion of data,
  4. processing restrictions,
  5. object to the processing of personal data,
  6. transfer of personal data,
  7. withdrawal of consent.

If you believe that we are processing your data contrary to legal requirements, you have the right to lodge a complaint with the supervisory authority – the President of the Personal Data Protection Office.

We process your data for the purpose of:

  1. handling your inquiry, pursuant to Article 6(1)(b) of the General Data Protection Regulation (GDPR);
  2. marketing purposes consisting in the promotion of our goods and services and ourselves in connection with the consent you have granted, pursuant to Article 6(1)(a) of the GDPR;
  3. securing or pursuing possible claims in connection with our legitimate interest, pursuant to Article 6(1)(f) of the GDPR.

Providing your data is voluntary . However, without it, you will not be able to send us a message, and we will not be able to respond to you.

We may transfer your data to trusted recipients:

  1. providers of tools for: website traffic analysis, sending marketing information.
  2. entities responsible for hosting (storing) the website and personal data.

We will process your data for the period of:

  1. necessary to achieve the specific purpose for which they were collected, and after its expiry for the period necessary to secure or pursue any claims
  2. in the case of data processing based on consent until its withdrawal. Withdrawal of consent does not affect the lawfulness of processing prior to withdrawal.

We do not process personal data in a way that would involve making solely automated decisions about you. More information regarding the processing of personal data can be found in our Privacy Policy.

The version without the prefix wins with a shorter, easier-to-remember address, and for small and medium-sized websites, the technical differences are marginal. If your site has been running for a while, keep the version that's already indexed and accumulating links – changing direction means a full migration of.

Three conditions for the correct implementation of domain redirection

Before adding any rule, check your server software. Popular guides rely on the .htaccess file, but this only works with Apache and LiteSpeed ​​– Nginx ignores it, and the rule simply doesn't change anything.

The second requirement concerns the SSL certificate . It must cover both names—the one with and without www. Negotiating an encrypted connection takes place before the server responds, so if the certificate only covers one version, a user accessing the other will see a browser warning before the redirection takes effect.

In what order should I set redirect rules?

The third requirement is order. First, route traffic from HTTP to HTTPS within the same hostname, and only then standardize the prefix . This arrangement avoids unnecessary redirect chains and is consistent with best practices for HSTS implementation.

Server, certificate and rule order – these three elements determine whether the redirection will work the first time.

301 redirects

How to redirect from www to non-www in .htaccess file?

The .htaccess file can be found in the website's root directory. If you don't see it, enable hidden files in your FTP client or create a new document with that name. The redirection is implemented by the following rule:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domenaxyz\.pl$ [NC]
RewriteRule ^(.*)$ https://domenaxyz.pl/ [R=301,L]

Notice two elements: The destination address begins with https, which prevents the user from being dropped from the encrypted connection . The fragment appends the subpage path to the new address – without it, each visit would end on the home page. In WordPress, place the rule above the block with the BEGIN WordPress comment to prevent the system from overwriting it. If the site is running behind a reverse proxy or on Cloudflare in Flexible SSL mode, the rules may loop – the conditions are then built on the X-Forwarded-Proto header, which forwards the actual protocol.

Redirecting from non-www to www – the reverse rule

When choosing the prefix version, swap both names:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domenaxyz\.pl$ [NC]
RewriteRule ^(.*)$ https://www.domenaxyz.pl/ [R=301,L]

Regardless of the direction, the rule must carry the full path and lead to an https address.

Domain redirection in Nginx, in the hosting panel and in the CMS

In Nginx, a redirect is defined as a separate block called server, which catches traffic to the unwanted hostname and returns a 301 with the full request path. Changing this requires access to the server configuration, so on shared hosting, the admin panel will be more convenient – ​​most providers provide a redirects section where you specify the source and destination addresses, and the 301 type.

Cloudflare offers a ready-made template for redirecting from www to the root domain. However, the rule will only work if there's a record for www in the DNS zone—without it, the browser will report an error before the request reaches Cloudflare.

The CMS itself can also help. WordPress enforces the chosen version through the site address fields in the general settings, PrestaShop has a preferred address format option, and Shopify automatically aligns the domain.

What not to use to redirect a domain?

Don't use meta refresh or JavaScript – they don't return an HTTP response code, so the search engine doesn't receive information about the permanent move. Choose a single implementation layer – server, dashboard, CDN, or CMS – and maintain the rule only there.

How to check if the redirect is working properly?

The quickest test is to run curl -I with the address of the old version. The response should return a 301 code and a Location header indicating the selected domain. Also check the address of any subpage – a lost path is the most common implementation error. Also, count the hops: a single redirect should lead to the target, not a chain of three.

Browsers remember 301 responses for a long time, making reverting an invalid rule difficult. It's safer to use a temporary 302 code during testing and replace it after confirming everything works. For final verification, use Google Search Console – URL Inspection will show which version the crawler considers canonical.

Just redirecting isn't the end of the job. After implementation, update any elements that still point to the old address:

  • sitemap.xml and its submission to Search Console,
  • internal linking and canonical tags,
  • destination addresses in Google Ads campaigns,
  • company business card and social media profiles,
  • data stream configuration in GA4.

Testing the subpage, checking the redirection chain and updating the addresses in the tools – only this set completes the implementation.

Domain Forwarding FAQs

Yes, although not because Google favors any one variant. As long as a page responds to two addresses, the external links and crawl budget are distributed across two hosts with the same content. A 301 redirect consolidates these signals into a single address and indicates the canonical version to the search engine.

For Google, both variants are equally important, so the decision is both technical and image-related. The version with the prefix allows you to set a CNAME record, which simplifies CDN use and moving a site between servers, while also streamlining cookie coverage. The address without www is shorter and easier to remember. If the site has been running for a while, keep the version that's already indexed and collecting links.

Most often, this is because the server doesn't read this file at all – Apache and LiteSpeed ​​handle .htaccess, while Nginx ignores it. On Nginx, the rule is defined in the server configuration, while on shared hosting, it's defined in the administration panel. In WordPress, also check if the rule is located below the WordPress BEGIN block, as the system can overwrite it.

Yes. An encrypted connection is negotiated before the server responds, so the browser checks the certificate before the redirect can take effect. If the certificate only covers one hostname, a user accessing the second hostname will see a warning instead of a page.

Call the old version's URL with curl -I and check for a 301 response and a Location header with the chosen domain. Repeat the test on any subpage, as a lost path is a common implementation error, and count the hops – a single redirect should lead to the target, not a chain. Finally, check the URL Inspection in Search Console to see which version the crawler considers canonical.

Anything that still shows the old address:

  • sitemap.xml and its submission to Search Console,
  • internal linking and canonical tags,
  • target addresses in advertising campaigns,
  • company business card and social media profiles,
  • data stream configuration in GA4.

For testing purposes, it is safer to use a temporary 302 code, because browsers remember the 301 response for a long time.

Summary

The above article covers the following topics:

  • Two versions of a domain scatter ranking signals, and the solution is a 301 redirect.
  • The version you choose depends on your DNS records, cookie coverage, and site indexing history.
  • Implementation requires checking the server type, SSL certificate for both names, and rule order.
  • You can configure the redirect in the .htaccess file, on Nginx, in your hosting panel, Cloudflare or CMS.
  • You can verify the rule's operation using the curl command, a subpage test, and URL Inspection in Search Console.