How to Redirect WWW to non-WWW URLs

Redirection is one of the most sensitive technical part in web development. A little mistake can not only break your website but also affects SEO negatively. Here I have discussed two different method on how to 301 redirect all www urls to non-www urls and non-www urls to www urls.

Steps to 301 Redirect WWW to non-WWW or Vice Versa

Simply follow these steps below to 301 redirect all urls to your desired version of urls. (www or non-www)

  1. Go to File Manager in cPanel or connect to your FTP
  2. Then go to the root directory where your website’s files are located.
  3. Find the .htaccess file and open it with any editor.
  4. Add the respective codes below in .htaccess
  5. You’re done!

Redirect to non-WWW

Add this code to your .htaccess to redirect all www urls to non-www urls. Replace “yourdomain.com” with your domain.

Redirect all www urls to non-www with .htaccess

Redirect to WWW

To redirect non-www urls to www urls, add this code to your .htaccess file.

Redirect all non-www urls to www with .htaccess

Conclusion

Serving all website contents either from www.yourdomain.com or from yourdomain.com is important. Now you can easily stick into one version.

Leave a Reply

Your email address will not be published. Required fields are marked *