This article explains how to configure a redirect so that visitors who type your root domain (e.g., example.com) are automatically sent to the "www" version of your site (e.g., www.example.com). This ensures a consistent user experience and helps consolidate your site's search engine presence.
Before you begin
You will need:
Access to your website's hosting control panel (such as cPanel or Windows Control Panel).
Access to your DNS management tool (if your DNS is managed outside of your hosting account).
The specific domain name you wish to redirect.
Redirecting via your hosting control panel
Most modern hosting panels provide a built-in tool to manage redirects. This is the recommended method as it handles the configuration automatically.
Log in to your hosting control panel.
Locate the Redirects or Redirects & Page Rules icon.
Select the domain or subdomain you want to redirect.
In the Type dropdown, select Permanent (301).
In the Redirects field, enter the destination URL (e.g.,
https://www.example.com).Click Add or Save.
Redirecting via .htaccess (cPanel/Apache)
If your hosting panel does not have a dedicated redirect tool, or if you prefer to manage it via your site's configuration files, you can use the .htaccess file.
Warning: Incorrectly editing the .htaccess file can cause your website to become inaccessible. Ensure you have a backup of the file before making changes.
Log use the File Manager in your control panel to navigate to your website's root directory (usually
public_html).Locate the
.htaccessfile. If it is not visible, ensure "Show Hidden Files" is enabled in your settings.Edit the
.htaccessfile and add the following code at the top of the file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Replace example.com with your actual domain name.
Save the changes to the file.
Redirecting via Windows Control Panel (IIS)
If you are using a Windows-based server, you can manage redirects through the IIS Manager.
Log in to the Windows Control Panel.
Select the website from the list.
Open the HTTP Redirect icon.
Check the box for Redirect all requests to...
Enter the destination URL (e.g.,
https://www.example.com).Select Permanent (301) as the redirect type.
Click Apply.
Confirm the result
To verify the redirect is working correctly:
Open a web browser and type your root domain (e.g.,
example.com) into the address bar.Press Enter.
The browser should automatically change the URL to the "www" version (e.g.,
www.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: If you recently changed your DNS records to point to a new server, it may take some time for the redirect to be visible to all users.
SSL Certificates: Ensure that your SSL certificate covers both the root domain and the "www" subdomain. If the certificate is missing for the root domain, users may see a security warning before the redirect occurs.
Caching: Your browser may cache the old redirect behavior. If the change doesn't appear immediately, clear your browser cache or test the site in an Incognito/Private window.
