How to Redirect WWW to non-WWW URL

In WordPress, the website URL of your site is the same as the URL set in General settings for WordPress Address (URL) and Site Address (URL) options. So on most of the Hosting servers, the default configuration from the server side will already make sure that the other versions of the URL (www or non-www) should redirect to the URLs set for the website in WordPress settings. However, sometimes it might not work as expected and you may see your site on both URLs (with www and without www) which is bad for SEO. So in this article, I will discuss two methods with you to set up redirect properly from www to the non-www version of the URL.

Set Redirect from CPanel

If your Hosting has CPanel then you can find the Redirects option in the Domains section of the CPanel.

CPanel Redirects Option

In Redirects settings, you can select the redirect type “Permanent(301)” and the domain for which you want to set redirect. In “Redirect to” field you can enter the URL of your site without www. Select “Only redirect with www” in the radio selection Options. Enable the “Wild Card Redirect” so that all pages from the www version of the URL will redirect to the same page in the non-www version of the URL. After the above settings click “Add” to save the Redirect.

redirect setttings - www to non-www

NOTE: If the above settings in CPanel do not work for you then use the second method as discussed below.

Use htaccess(for apache servers only)

This method is only recommended if you have access to server files or CPanel. You will find htaccess file in the root directory(mostly named as public_html but can be different) of the site. You can add the below lines of code in your htaccess file and save changes.

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

In the above code replace “www.learnadvancedwp.com” with the www version of your site’s URL and replace “https://learnadvancedwp.com” with the non-www version of your site’s URL.

This method will work for most users. However, depending upon already existing htaccess configuration, adding the above lines of code can result in 500 Internal Server Error as well that’s why it’s important to not edit htaccess file directly from the WP dashboard using plugins like “File Manager” because in this case, you can lose access to the site in case of Error. So it’s important that you should have FTP access or access to Hosting CPanel before implementing changes in htaccess.

I hope this article has helped you to Redirect WWW to the non-WWW URL of the site and prevent duplicate versions of the same pages to avoid SEO issues.

If you have any questions, feel free to ask in the Comment section.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *