How to Remove WWW From URL through htaccess

How to remove www from url through htaccess. Suppose, if a user type http://www.example.com (example is the name of your domain) in their browser, you can automatically redirect them to http://example.com.

For website SEO (Search Engine Optimization) purpose, it is necessary that your blog or website either respond to http://www.example.com or http://example.com, but not both. Otherwise, search engines see duplicate content on the www and non-www domains, and may downgrade the site ranking.

In my previous posts, I have explained htaccess file and their importance. In this post, We will learn how to remove www from url through htaccess.

Create SEO friendly URL through .htaccess

Password protect folder through .htaccess

Prevent Image hotlinking

Leverage Browser Caching

How to Remove WWW From URL through .htaccess

To remove www from Url . Put this code in your .htaccess file.

I have mentioned my domain webrewrite.com in htaccess. You can replace and put your domain name in place of webrewrite.com. Above htaccess directives remove www from Url.

You can also use this snippet as well.

301 is HTTP status code which means permanent redirection from an old Url to a new Url. It is very important in terms of website SEO. This HTTP status code tells search engines that your site is moved from old Url to a new Url.

For example –  My website previous Url is https://www.webrewrite.com. Now, I have removed www  from website Url (https://webrewrite.com), so I am using 301 . HTTP status code 301 redirect is very useful in terms of SEO as it passes the web authority of our old Url to  a new Url.

Tagged . Bookmark the permalink.

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.