The steps below detail two ways make WordPress use only www for your website address.
If a user tries to access your website using the non-www address they will be automatically directed to the www address.
Method 1: using wp-config.php
Please note, if you have the WordPress files in a sub-folder, for example domainname.com/wordpress but want users to access your site using domainname.com – you will need to set WP_HOME to the sub-folder and WP_SITEURL to the address for the website.
- Using FTP or your websites cPanel access, open the wp-config.php file in the root of your WordPress installation
- At the top of the file, below the <?php add the following code
-
define('WP_HOME','http://www.domainname.com'); define('WP_SITEURL','http://www.domainname.com');
- Replace ‘domainname.com’ with the new domain name for your website.
- Save the changes and try accessing your site from the non-www address
- The page should automatically redirect to the www address.
Method 2: using wp-admin
Please note, if you have the WordPress files in a sub-folder, for example domainname.com/wordpress but want users to access your site using domainname.com – you will need to set WordPress Address (URL) to the sub-folder and WordPress Site (URL) to the address for the website.
- Log into your wp-admin
- Browse to ‘Settings’ -> ‘General’
- Under ‘WordPress Address (URL)’ and ‘Site Address (URL)’ add www to the address as shown below
- Save the changes and try accessing your site from the non-www address
- The page should automatically redirect to the www address.
Method 3: using .htaccess
Apache hosted websites (the most common type) can also configure a server configuration file called .htaccess
To do this you will need access to the files on the server. You should find it at the ‘root directory’ for your website (where WordPress was installed).
If you’re not sure about this – contact your website host for assistance.
Adding the following code to the top of your .htaccess will automatically redirect non-www to www (including https being enforced).
# Redirect non-www traffic to www & enforce https RewriteCond %{HTTP_HOST} !^www. RewriteCond %{HTTP_HOST} !^static. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]