As a cPanel user, you have the capability to compel users to redirect from the www to non-www URL, or vice versa, for your domain. Simply add a directive in the .htaccess file to implement the desired redirection.
Redirecting www to Non-www URLs using .htaccess:
-
Access your cPanel account.
-
Create or edit the .htaccess file in the document root of your domain through File Manager.
-
Add the following code to the file's conclusion:
# Redirect www URLs to non-www URLs - like http://www.yourdomain.com to http://yourdomain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.yourdomain\.com [NC]
RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]
-
After selecting "Save Changes," close the file.
Redirecting Non-www to www URLs using .htaccess:
-
Access your cPanel account.
-
Create or edit the .htaccess file in the document root of your domain through File Manager.
-
Add the code that follows to the end of the file:
# Redirect non-www URLs to www URLs - like http://yourdomain.com to http://www.yourdomain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com [NC]
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]
-
Save your changes and close the file.
Note: If there is an existing redirection directive in the .htaccess file, you must replace it to modify the redirection target.