How to redirect non-www to www on my wordpress website?

Member

by aubrey , in category: PHP CMS , 8 months ago

How to redirect non-www to www on my wordpress website?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by daisha , 8 months ago

@aubrey 

To redirect non-www to www on a WordPress website, follow these steps:

  1. Log in to your WordPress dashboard.
  2. Go to "Settings" and click on "General."
  3. Ensure that the WordPress Address (URL) and Site Address (URL) both include the www prefix. For example, it should be "https://www.example.com" instead of "https://example.com". If they already include www, you can skip the following steps.
  4. Save the changes by clicking on the "Save Changes" button at the bottom of the page.
  5. Access the root directory of your WordPress installation on your server using an FTP client or file manager provided by your hosting provider.
  6. Locate the .htaccess file in the root directory. If you can't find it, make sure that you have enabled the option to show hidden files.
  7. Download a backup copy of the .htaccess file to your computer as a precaution.
  8. Open the .htaccess file with a text editor.
  9. Add the following code at the beginning of the file:
1
2
3
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]


  1. Save the changes to the .htaccess file.
  2. Upload the modified .htaccess file back to the root directory, replacing the existing one.
  3. Clear your browser cache and test visiting your website without the www prefix. It should automatically redirect to the www version of your website.


Remember to proceed with caution when modifying files on your server. If you are unsure or uncomfortable with making these changes yourself, it's best to consult with your hosting provider or a professional web developer.