How to Redirect all non www request to www

How to Redirect all non-www requests to www 

 

Redirecting all non-www requests to www can help ensure that your website has consistent URLs and avoid duplicate content issues. Here is an example of how to do it using the htaccess-file :

RewriteEngine On RewriteCond %{HTTP_HOST} !^www. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

This code tells the server to redirect any requests that don't start with "www" to the same URL but with "www" added to the beginning. For example, "yourdomain.com" would be redirected to "www.yourdomain.com".

By doing this, search engines will recognize all variations of your website's URL as the same, which can help improve your website's search engine optimization (SEO).

 

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

 

Please comment and share this course and thanks for reading ❤️❤️❤️.


Please Share this course

It Looks like you have completed your course!! We have created Online series based on the above content. You can give a test and check your skill.




Be a Part of CollegeSpike by giving your precious comment here and help us in improving our content.