Skip to main content

How to Redirect a "www" Domain to the Root Domain

How to Redirect a "www" Domain to the Root Domain This article explains how to configure a redirect so that visitors who type "www." before your domain name are automatically sent to the root domain (the version without "www."). This ensures a consistent

This article explains how to configure a redirect so that visitors who type "www." before your domain name are automatically sent to the root domain (the version without "www."). This ensures a consistent user experience and helps consolidate your site's authority.

Before you begin

You will need:

  • Access to your website's hosting control panel (such as cPanel or Windows Control Panel).

  • Access to your website's configuration files or a web server configuration tool.

  • Your domain name (e.g., example.com).

Configure the redirect via .htaccess

If your website is hosted on a Linux-based server using Apache (the standard for most cPanel accounts), you can use the .htaccess file to manage the redirect.

  1. Log in to your hosting control panel.

  2. Open the File Manager.

  3. Navigate to the root directory of your website (usually public_html).

  4. Locate the .htaccess file. If it does not exist, you may need to enable "Show Hidden Files" in your File Manager settings.

  5. Select the .htaccess file and click Edit.

  6. Add the following code to the top of the file:

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

7. Save the changes.

Configure the redirect via Windows Control Panel (IIS)

If your website is hosted on a Windows server using IIS, you can use the Web Redirect module or a rewrite rule.

  1. Log in to the Windows Control Panel.

  2. Select the domain you wish to modify.

  3. Navigate to Web Redirect or the Rewrite section.

  4. Create a new rule or edit the existing one to redirect www.example.com to https://example.com.

  5. Ensure the redirect type is set to Permanent (301).

  6. Save the settings.

Confirm the result

To verify that the redirect is working correctly:

  • Open a web browser and type www.example.com into the address bar.

  • Press Enter.

  • The browser should automatically change the URL to https://example.com and load the page.

  • You can also use a tool like "Redirect Checker" to confirm that the server is sending a 301 Moved Permanently status code.

Limitations

  • DNS Propagation: While the redirect happens at the server level, changes to DNS records (if you are changing where the "www" record points) may take time to propagate across the internet.

  • Caching: Your browser may cache the previous redirect behavior. If the redirect does not appear to work immediately, clear your browser cache or test the URL in an Incognito/Private window.

  • SSL Certificates: Ensure your SSL certificate covers both the www and non-www versions of your domain to avoid security warnings during the redirect process.

Did this answer your question?