.htaccess Remove “www” from URL

Here is a quick and easy code you can use in your .htaccess file, located in the root directory of your website, to remove any world-wide web letters from your url. This will remove “www” from all your website’s pages as well as search engines, etc.

[code lang=”apache”]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mywebsite.com$ [NC]
RewriteRule ^(.*)$ http://mywebsite.com/$1 [R=301,L]
[/code]

And vice-versa you can add “www” to your website’s url with the following .htaccess code:

[code lang=”apache”]
RewriteEngine on
Options FollowSymlinks
Rewritecond %{HTTP_HOST} ^mywebsite.com [NC]
Rewriterule ^(.*)$ http://www.mywebsite.com/$1 [R=301,NC]
[/code]

All I did here was switch the places of the url of with “www” and the url without “www” in the code.

Just replace “mywebsite.com” with your website’s domain name.

Filed under: Web ProgrammingTagged with:

5 Comments

  1. Its very informative and interesting article.all the points are very useful. Simple but very effective writing. Thanks for sharing such a nice post.

  2. This is my first time i visit here. I found so many entertaining stuff in your blog, especially its discussion. From the tons of comments on your articles, I guess I am not the only one having all the leisure here! Keep up the excellent work.

  3. This is a really good read for me. Must admit that you are one of the coolest bloggers I ever saw. Thanks for posting this informative article.


Add a Comment

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

Comment *
Name *
Email *
Website