Quantcast
Channel: KWS Blog » htaccess
Viewing all articles
Browse latest Browse all 5

How to Add www. – or Remove www. – From Your URL

$
0
0
Add or remove .www from your site's address

This has been done many times by others, but just a quick tip on how to add or remove www. from your website’s address. This is helpful for URL canonicalization and user experience consistency. You can also achieve SEO-friendly canonicalization using rel="canonical". Oh boy, I’m getting too technical :-)

Here’s the juicy part:

Add the following to the .htaccess file in your website’s root folder (often named public_html or www). If there’s not a file named .htaccess, you may create it. If you are creating the .htaccess file, set the permissions to 644. For security reasons, you don’t want others to be able to write to this file.

Note: These snippets are for http:// only, not secure https:// URLs.

Add www.


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com/?(.+)?$
RewriteRule ^(.*)$ "http\:\/\/www\.example\.com/$1" [R=301,L]

Remove www.


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

This will work with the majority of web hosts in my experience, but not all.

Additional resources

For more .htaccess information, and great follow-up reading on .htaccess, check out corz.org’s tutorial and second tutorial on some of the most-used .htaccess tricks.

The post How to Add www. – or Remove www. – From Your URL appeared first on KWS Blog.


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>