WordPress WWW and non-WWW issue

How to redirect your WordPress site’s domain from non-www to www or vice versa. It is recommended that keep hostname of your website same throughout. Either use the www or without the www.

To redirect non-www to www

  1. Login to the dashboard of your WordPress website.
  2. Go to settings and then general.
  3. Locate the following fields:
    WordPress Address (URL): http://yourwebsite.com
    Site Address (URL): http://yourwebsite.com
  4. Replace both URL with adding www.
    WordPress Address (URL): http://yourwebsite.com
    Site Address (URL): http://yourwebsite.com
  5. Save setting.
    Now you will redirect to www version. you can see in url that www has been added.

Using .htaccess to redirect non-www to www