Skip to content

www and https redirect: how to make your site work on one address

Medium 30 min Updated:

Quick answer

To make your site work on a single address, you need to choose the canonical version (e.g. https://www.example.com) and permanently redirect all other variants (http, non-www) to it using a 301 redirect. This is most often done at the hosting level or in the `.htaccess` file, and then you check whether all variants are correctly redirected.

How to recognize the problem

  • The site opens on both www and non-www addresses with the same content
  • The http version of the site is not redirected to https
  • Google shows different versions of URLs in search results
  • When you type the address without www, the site loads but the address bar does not change
  • There are duplicate entries in Google Search Console or Analytics

Most common causes

No redirect configured

The hosting or server is not configured to redirect one version to the other, so both load independently.

Incorrectly configured SSL certificate

The certificate is issued for only one variant (e.g. without www), so the other does not load over https or shows an error.

Multiple A records or CNAME records

DNS records point to different servers or IP addresses, so the site behaves inconsistently depending on what is cached.

CMS or plugin forces a different address

WordPress or a plugin has a different base address set (Site Address), which causes a redirect loop or duplication.

Browser or CDN cache

Old 301 or 302 records remain in the cache, so it seems the redirect is not working even though it is correct on the server.

Step-by-step fix

  1. 1

    Choose the canonical address

    Decide whether the site will officially be at https://www.example.com or https://example.com. The recommendation is to use the https version, and www or non-www is a matter of habit; the most important thing is consistency. Write down your choice because it will be used in all subsequent steps.

  2. 2

    Check the current state

    Open all four combinations: http://example.com, http://www.example.com, https://example.com and https://www.example.com. Note which ones load directly, which show an error, and whether the address in the browser changes. This will tell you what is already configured.

  3. 3

    Set up the redirect in the hosting panel

    In cPanel or a similar panel, look for the Redirects option. Choose the source (e.g. example.com) and the destination (https://www.example.com), type 301 (permanent). If the hosting offers automatic https forcing, enable that option too. Wait a few minutes and then check.

  4. 4

    Or add rules to .htaccess

    If you do not have a panel or want more precise control, make a copy of the .htaccess file before making changes. In the site root, open .htaccess and add rules to redirect http to https and non-www to www (or vice versa). Example for www and https: RewriteEngine On, RewriteCond %{HTTPS} off [OR], RewriteCond %{HTTP_HOST} !^www\. [NC], RewriteRule ^ https://www.example.com%{REQUEST_URI} [L,R=301]. Save the file and test.

  5. 5

    Check that WordPress has the same address

    In WordPress, go to Settings > General and check that WordPress Address (URL) and Site Address (URL) are identical to the canonical address. If they are not, back up the database and files before making changes, then correct them. Also check whether any security or caching plugin forces a different redirect.

  6. 6

    Clear the cache

    Clear the browser cache (on Windows/Linux press Ctrl+Shift+Delete, on macOS Command+Shift+Delete), the CDN cache if you use one, and the cache of plugins on the site. Then reopen all four variants in private browsing mode. The address in the address bar should change to the canonical one.

  7. 7

    Check the status codes

    Use an HTTP header checking tool (e.g. an online HTTP header checker) or the command line curl -I http://example.com. The response should be 301 Moved Permanently with a location to the canonical address. Repeat for all variants.

  8. 8

    Update Google Search Console

    In Google Search Console, add the new canonical address as a property (if not already). Then submit a new sitemap and request indexing of key pages. Google does not use a special "preferred" address setting; it accepts the canonical address based on 301 redirects and canonical tags. Old variants will gradually disappear from the index.

  9. 9

    Check for redirect loops

    If the page does not open or shows a "too many redirects" error, there is probably a conflict between .htaccess rules, the WordPress address, and plugins. Disable caching and security plugins one by one and check whether the problem is resolved.

If nothing helps: server and CDN level check

If you have tried all the steps and the redirect still does not work, the problem may be in the server configuration (nginx, Apache virtual host) or the CDN service (Cloudflare and similar). In that case, contact hosting support and specify exactly which address variants behave incorrectly. If you use Cloudflare, check whether the "Always Use HTTPS" option is enabled and whether there are Cloudflare rules (Page Rules or newer Rules) that change the behavior. Also, check whether there are multiple A records for the domain pointing to different servers; this can cause inconsistent redirects. For advanced users, checking access logs can reveal whether requests even reach the server or are lost at the CDN.

How to prevent it

  • Regularly check whether the site opens on all address variants and whether they are redirected.
  • After every DNS or hosting change, test the redirect in private browsing mode.
  • Use a site uptime monitoring tool that will notify you if an error or a non-redirected version appears.
  • Write down the canonical address and stick to it in all marketing materials and on social media.

When to call a professional

If you do not have access to the hosting panel or .htaccess file, or if the problem persists despite all steps, contact IT support or the hosting administrator. They can check the server and CDN configuration and solve the problem faster and without the risk of additional errors.

Website development · Fast, SEO-ready, multilingual websites

FAQ

Is it better to use a www or non-www address?

Both options are technically correct. It is important to choose one and use it consistently. Many prefer www because it separates subdomains more easily, but that is not mandatory.

How long does it take for Google to accept the new address?

Usually from a few days to a few weeks, depending on the size of the site and the indexing frequency. Check Search Console regularly and wait patiently.

Does a 301 redirect affect SEO?

A proper 301 redirect transfers most of the SEO value to the new address and prevents duplicate content. That is why it is important that it is permanent (301), not temporary (302).

Share
Didn't find a fix?The AI IT assistant is available 24/7. Describe the problem or send a screenshot of the error and get instructions for your case.Ask the AI IT assistant