Pre-requirements:

  • Access to cPanel or Plesk dashboard with administrative rights.
  • A domain with SSL enabled for both the naked domain (example_domain.com) and the "www" version (www.example_domain.com).
  • Basic knowledge of Apache's .htaccess or virtual host configuration (for CLI steps).

Step-by-Step Guide for cPanel

1. Redirect WWW to Naked Domain Using the cPanel User Interface (UI)

  1. Log in to your cPanel dashboard.
  2. Under the Domains section, click on Redirects.
  3. In the Add Redirect section:
    • Choose Permanent (301) as the redirect type.
    • Select your domain from the dropdown menu (e.g., www.example_domain.com).
    • In the Redirects to field, enter your naked domain (e.g., https://example_domain.com).
    • Ensure the redirect applies to All Public Domains.
    • Click Add to save your redirect.
  4. Test the redirection by visiting both www.example_domain.com and example_domain.com. Ensure that both are redirecting to the naked domain.

2. Redirect WWW to Naked Domain Using the cPanel CLI

  1. Log in to your server via SSH as the root user.
  2. Navigate to your website's document root:
    cd /home/$user/public_html/
  3. Open (or create) the .htaccess file:
    vi .htaccess
  4. Add the following code to redirect the "www" version to the naked domain:
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
            
  5. Save and close the file, then restart Apache:
    sudo /usr/local/cpanel/scripts/restartsrv_apache --restart
  6. Test the redirection by visiting www.example_domain.com to confirm it redirects to example_domain.com.

Step-by-Step Guide for Plesk

1. Redirect WWW to Naked Domain Using the Plesk User Interface (UI)

  1. Log in to your Plesk control panel.
  2. In the left-hand sidebar, go to Domains, and select the domain you want to edit.
  3. Click on Hosting Settings.
  4. Under the WWW redirection section, set the option to redirect from www.example_domain.com to example_domain.com.
  5. Click OK to apply the changes.
  6. Test the redirection by visiting both www.example_domain.com and example_domain.com. Ensure both are redirecting to the naked domain.

2. Redirect WWW to Naked Domain Using the Plesk CLI

  1. Log in to your server via SSH as the root user.
  2. Navigate to the domain's web directory:
    cd /var/www/vhosts/example_domain.com/httpdocs/
  3. Open (or create) the .htaccess file:
    vi .htaccess
  4. Add the following code to the file to redirect the "www" version to the naked domain:
    
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
            
  5. Save and close the file, then restart Apache:
    sudo systemctl restart httpd
  6. Test the redirection by visiting www.example_domain.com and ensuring it redirects to example_domain.com.

Common Gotchas to Avoid

  • Ensure your SSL certificates are properly configured for both the "www" and naked domains to avoid security warnings.
  • Always use a 301 redirect for permanent redirections. This ensures search engines update their records to reflect the naked domain.
  • Test thoroughly using different devices and browsers to ensure the redirect works as expected across the board.
Did this answer help? 0 People found this helpful (0 Votes)