WordPress – How to force website to use www

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.

Option 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.

  1. Using FTP or your websites cPanel access, open the wp-config.php file in the root of your WordPress installation
  2. At the top of the file, below the <?php add the following code
  3. define('WP_HOME','http://www.domainname.com');
    define('WP_SITEURL','http://www.domainname.com');
  4. Replace ‘domainname.com’ with the new domain name for your website.
  5. WordPress-ChangeDomain2
  6. Save the changes and try accessing your site from the non-www address
  7. The page should automatically redirect to the www address.

Option 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.

  1. Log into your wp-admin
  2. Browse to ‘Settings’ -> ‘General’
  3. Under ‘WordPress Address (URL)’ and ‘Site Address (URL)’ add www to the address as shown below
  4. Save the changes and try accessing your site from the non-www address
  5. The page should automatically redirect to the www address.

WordPress-ChangeDomain1