When installing a WordPress site, you can choose to install on primary domain, subdirectory or in a subdomain. However, the missing point here is that www is actually a subdomain which many hosting companies do not consider. For example, when you install WordPress from SiteGround Site Tools section on your domain, it will by default consider non-www version of your site. The good part is that you can easily change this to force non-www to www version of your WordPress site.
Non-www and WWW Versions
Before moving ahead, first let us explain about www and non-www versions and why you should use a proper version.
- WWW version of – https://www.webnots.com/
- WWW version – https://tools.webnots.com/
- Non-www version – https://webnots.com/
When you compare the above URLs, it is easy to understand that www and tools are actually subdomains of the primary domain webnots.com. Therefore, search engines consider www and non-www versions of the same site as two different sites.
Problem with WWW and Non-www versions
By looking at the outset, both www and non-www versions may look similar and will not create any problems. This is true when you always use one single version for all your subdomain and subdirectory WordPress installations. Otherwise, you will see the domains appearing separately in all your reporting like AdSense and Search Console.
- Your XML Sitemap should belong to the correct version you use on the site. Otherwise, it will fail to process and your pages will not be crawled properly.
- In AdSense, Analytics and wherever you add the domain name, make sure to add the correct one with or without www version.
- You need www version for using certain options like Cloudflare setup with SiteGround hosting. This is funny as you can add www and non-www versions in Cloudflare directly while SiteGround force you to use www version.
- You need to install SSL on the correct domain to avoid not secure warnings in browsers.
Search engines may also consider that you are trying to trick them by showing different content in www and non-www versions. Otherwise, it will end up in duplicate content when both www and non-www versions are accessible.
Force Non-www to WWW Version in WordPress
In summary, it will create a big mess unless you are careful at the beginning to install WordPress properly on your preferred domain and follow the same domain for submitting to search engines. If you choose to use WWW but your default WordPress installation is setup on non-www versions, here are the options for you.
1. Change Site URLs from WordPress Admin Panel
This is the super easy option which you can do as an administrator of your site.
- Login to your WordPress admin panel and navigate to “Settings > General” section.
- Check “WordPress Address (URL)” and “Site Address (URL)” boxes. Here you should be seeing non-www versions of your URLs.
- Change both these URLs with correct www version. Also, make sure to enter correct HTTPS version.
- Go to the bottom of the page and click “Save Changes” button.
- You will be instantly logged out of the admin panel as the URL is changed.
- Now you can login back using the URL link https://www.yoursite.com/wp-admin/.
2. Using wp-config.php to Update WWW Version
If you are not able to access admin panel, or comfortable in working with hosting panel then you can follow this option.
- Login to your hosting panel and open File Manager app.
- Navigate to the root directory of your WordPress installation. If you have installed on primary domain, then it should be “/public_html/”.
- Find wp-config.php file and click on the edit option.
- Add the following lines before it says, “/* That’s all, stop editing! Happy publishing. */”.
- Save your changes and login try to login to your admin panel with www version.
define('WP_HOME','https://www.yoursite.com');
define('WP_SITEURL','https://www.yoursite.com');
It will look like below in the File Manager.
3. Change WWW version with phpMyAdmin Tool
WordPress stores the site address and WordPress address URLs in wp_options table. You can directly edit these values in your database to update the www version for your site.
- When you are in your hosting account, search and open phpMyAdmin tool.
- Click the database of your site and then click “wp_options” table. Note that the wp_ is a default prefix for WordPress tables. However, it may be different on your installation as many hosting companies change this prefix as a security measure.
- You can find the “siteurl” and “home” as first two items of option_name in the table.
- Click on the option_value box for these items and change with correct www version.
4, Force WWW with .htaccess Redirect
The last option is to use .htaccess redirect and force all URLs on your site to use www prefix.
- When you are in the hosting account, find and open File Manager app.
- Navigate to the root location of your site and edit .htaccess file.
- Paste the following code at the end and save the changes.
#Force WWW Version:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
RewriteRule ^(.*)$ https://www.yoursite.com/$1 [L,R=301,NC]
It should look like below in .htaccess file in the File Manager app:
Final Words
After using one of the above options, you should be able to use www version of the site. You can use .htaccess directive and one of the other options to make sure your non-www version is always forced to www version. This will help if you have already mixed the version for different WordPress installation on primary domain, subdirectories or on subdomains. If you want to force non-www version, then make sure to use one of the first three options and change the URLs with non-www version.
1 Comment
Leave your reply.