Add to Favorites

Hosting Toolbox Tip - .htaccess Files Are Your Friend

So often your web host limits the amount of functionality you are able to access at the server level.

Perhaps you have a shared hosting account and want to be able to do some advanced functions, but you don't have access to configure the server.  Well there are some tools to help you manipulate functions within your web directories using the infamous .htacess file.

.htaccess is simply a file that can be placed in any folder to tell the web server how to handle files in that folder.

.htaccess files can be used for:

  • error handling
  • file redirection
  • password protecting
  • file root directory structure
  • file parsing
  • and many other things

Today I'll just share a little bit about domain "www" redirection.

What's cool about this little trick is that it is also known to be pleasing to Google because Google does not want to index two versions of your website - a www version and a non www version for example.

.htaccess can force your site to always redirect to www. Just use this snippet of code in your .htaccess file:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$$1 [L,R=301] 

This will redirect anyone using the non-www address to the www version, and Google will only index one version of your site.


Be the first to leave a comment on this post.

Leave a comment

To leave a comment, please log in / sign up