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)
- Go to File Manager in cPanel or connect to your FTP
- Then go to the root directory where your website’s files are located.
- Find the .htaccess file and open it with any editor.
- Add the respective codes below in .htaccess
- 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 to WWW
To redirect non-www urls to www urls, add this code to your .htaccess file.
Serving all website contents either from www.yourdomain.com or from yourdomain.com is important. Now you can easily stick into one version.