.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.

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

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

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

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.

0

Popularity: 1% [?]

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Filed Under: Web Programming

Tags:

RSSComments (5)

Leave a Reply | Trackback URL

  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. I like the layout of your blog and Im going to do the same for mine. Do you have any tips? Please PM ME.

  3. 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.

  4. 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.

  5. Useful article can i translate into French for my sites readers? Thanks

Leave a Reply




If you want a picture to show with your comment, go get a Gravatar.

The tutorials and scripts found on bgallz.org are for training purposes only, use to your discretion.