How to redirect www URLs to non-www

In this post, We going to see how to redirect www URLs to non-www. They are two URLs for the domain one is www and another one non-www but these two URLs are different, In case you have both of them in the .htaccess file the server confuse to redirect to the page and it also affects your (SEO)Search Engine Optimization and ranking. So before doing this chose the correct method you need to redirect.
You can redirect all the www request to non-www by modifying your website’s using .htaccess. Add the following code at the beginning of the file so that the redirection is properly works and the main thing you need to replace yourdomain.com with your exact domain name. Right click and edit the .htaccess file using Editor view.
Here below the code:
1 2 3 |
RewriteEngine On RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC] RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301] |
From now on, when visitors access http://www.yourdomain.com that will be redirected to http://yourdomain.com.
.htaccessawscloud serverserver
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]