How To Redirect From Domain.com To Www.domain.com Using .htaccess

How to Redirect domain.com to www.domain.com

Redirecting domain.com to www.domain.com is recommended for SEO, brand consistency, and preventing duplicate content issues. This guide explains how to configure redirects correctly on modern hosting platforms including cPanel (Linux) and Plesk Obsidian 2022+ (Linux and Windows IIS).


1. cPanel (Linux Hosting)

cPanel uses Apache, so redirects are applied using a .htaccess file inside your public_html directory.

Step A: Locate or create your .htaccess file

  • Log in to cPanel.
  • Open File Manager.
  • Open the public_html folder.
  • If .htaccess does not exist, create it.

Step B: Add this redirect rule (modern and secure):

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

Replace domain.com with your actual domain name. This forces HTTPS and a permanent SEO friendly redirect.


2. Plesk Obsidian 2022+ (Linux Hosting)

On Plesk Linux hosting, redirects also use .htaccess located inside the httpdocs directory.

  • Log in to Plesk.
  • Open Files.
  • Go to httpdocs.
  • Edit or create the .htaccess file.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 - [L,R=301]

Use this if your site runs Apache (default for Plesk Linux).


3. Plesk Obsidian 2022+ (Windows Hosting - IIS)

On Windows hosting, .htaccess does not work. Apache rewrite modules are not available because IIS manages redirects through web.config.

Add the following XML rule to your web.config file located in httpdocs:

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url="(.*)" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain\.com$" />
          </conditions>
          <action type="Redirect" url="https://www.domain.com/{R:1}" redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

This is the officially recommended IIS URL Rewrite method for a permanent and secure redirect.


4. Best Practices (2025 Hosting Standards)

  • Always replace domain.com with your actual domain.
  • Always use 301 redirects for SEO.
  • Use HTTPS only after installing an SSL certificate.
  • Fast2Host includes free AutoSSL for cPanel and Plesk Linux.
  • Clear your browser cache after applying redirects.

Secure Your Website with Premium SSL Certificates

Fast2host offers FREE AutoSSL certificates in cPanel and Plesk Linux, plus premium EV, OV and Wildcard SSL options at:

View SSL Options →
Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 12465

Need more information or have a question ?