Force WordPress to www URL

In WordPress by DaveLeave a Comment

It is best practice to choose a URL structure for your website so the same URL shows every time. There has been great discussion on whether or not to use the www portion in your URL. Some say it is obsolete and takes up space while others in favor of keeping the www say it is important to follow standards. Others argue that SEO benefits are to blame for their decision to keep or do away with the www. As of the writing of this article most SEO professionals have concluded that there is no difference either way. Nonetheless if you have a WordPress website you may find that you need to make the choice. We have found the best way to force either www or non-www is as simple as making two line changes in your WordPress wp-config.php file.

To force www in your URL add (or edit) the following lines in your wp-config.php file.

define('WP_HOME','http://www.domainname.com');
define('WP_SITEURL','http://www.domainname.com');

To force non-www in your URL add (or edit) the following lines in your wp-config.php file.

define('WP_HOME','http://domainname.com');
define('WP_SITEURL','http://domainname.com');

After you are finished making your updates to the wp-config.php file, save it and then restart Apache. Your URL should now force to resolve to the structure you have chosen.

Leave a Comment