.htaccess basics

Previously I have written articles on .htaccess, they are:

But since not all of you know how to use and modify .htaccess file on your server, I am writing this basic htaccess tutorial.

What is this (htaccess) file and what does it do?

It is a file for managing directories on the web server (i.e your web hosting). the name htaccess comes from “hypertext access”. With htaccess, you can do many things, like:

  • Defining your error documents (eg. 404 errors)
  • Password protecting your directories
  • Blocking users by IP
  • Blocking traffic from certain sites
  • Blocking bad bots (eg. spammers)
  • Preventing hotlinking of your images
  • Redirecting pages to another
  • and many more

Where is this file?

.htaccess is a file that is usually found in your root directory. If your web-host allows you to see it, you can see the file together with your other files in your root folder (see below). However sometimes web-hosts do make them hidden (so that you don’t accidentally modify it or delete it).

htaccess_file.png

You can also create different .htaccess files for different sub-folders on your website. It doesn’t necessarily have to be in the root folder. However htaccess directives in the root folder will apply automatically to all sub-folders, so you have to be careful of what you do with it. For example, blocking google.com will be a nightmare to most sites. Especially if you are an e-commerce site that rely on Google traffic.

How to create them?

htaccess files can be created by notepad. Here is a sample htaccess file from my adesdesign.net site.

htaccesssample.pngYou can see that in my htaccess file I have defined Error files, and also have redirected adesdesign.net to www. adesdesign,net (with www). As you know URL with and without “www” are considered two different websites to the search engines. Therefore redirecting one to another is very important. Here is how you can do that.

htaccesssave.pngSo, creating htaccess file is easy. Just open the notepad, type in your commands and save it as .htacess (yes with dot in front) for the file name and select “all files” for file type as shown in the screenshot to the right. Save.

I hope you find this article useful. Do let me know if you have any questions in the comments section.

Subscribe to RSS: click here.



18 Comments on ".htaccess basics"

  1. balootisme says:

    this is what i need to change permalink from default url to seo friendly url

    thanks ades…

    but, i can’t found file .htaccess on my blog folder files…and on my public_html file too…

    how?

  2. Ades says:

    balootisme, which means your htaccess file is hidden. you can create a new one and upload it to your server. after you upload you might not be able to see it, since it’s hidden at the moment.

    [as usual, be careful when working with your htaccess file]

  3. Rajaie says:

    Hey Ades, great article, but when I try to access “Why you should redirect yourblog,com to www,yourblog.com” the article is all messed up with weird characters.

    Any idea how to fix it?

  4. Ades says:

    Rajaie, it’s now fixed.

  5. Rajaie says:

    Sorry, but it’s still the same

  6. Ades says:

    Try deleting your browser cache Rajaie

  7. Rajaie says:

    It works, thanks :-)

  8. Great post as usual. I did not know that we could block users, with this, from particular IP addresses, will chat to our developer. Thanks

  9. Yan says:

    Hi Ades,

    I’d like to know that if I set the WordPress address (URL) and Blog address (URL) on my Admin > Setting as thoushallblog.com, do I still need to edit my .htaccess?

  10. Ades says:

    yes yan you still need to, because you don’t know how people type your url. some type it with www and some without. so by editing your htaccess you standardize your urls

  11. Yan says:

    Thanks for your prompt reply. But in which situation people will type the url with www when each time I only show without www?

  12. Ades says:

    well, you can’t control people’s behavior right? if they feel like typing www in front of your url, what can you do? that’s where htaccess comes… besides if you do not combine them, you will lose out on the SEO thing

  13. Yan says:

    Yes, you have your point. Thanks for the helpful tips.

  14. It works! Thanks man .good!

  15. I’ve also used .htacess on my sites to redirect all pages to just the www. format so that a regular http://... address and http://www…. address don’t get listed twice by the search engines.

    If this happens for every page on your blog, you can end up with stuff getting de-indexed for dupe content

  16. I’m beginning to wonder if this is the reason I lose my ranking out of a sudden. I was on the top 10 for ‘blog for beginners’ and now I was not even in the next 100 for that keyword.

    What amazes me more is the fact that I wasn’t even in the first page for keyword ‘thoushallblog’ if you know what I mean..

    Sad but it’s true.

  17. Thanks for sharing. I never thought that making changes in htaccess file is so easy. I was about to hire a website programmer to help me to redirect my pages but thanks to you, i no longer need to.

Trackbacks for this post

  1. Setting up a bouncer at your door to your blog | Autumn At Oak Hollow

Got something to say? Go for it!