Posted by & filed under Programming.

One of the hardest things I learned while working on web development was the .htaccess file. Sure, I found tutorials everywhere, but most of them were written in a language I didn’t understand (remember, I was new to web development). So, here is a simplified tutorial on .htaccess and what it can do.

Host Support
First, you need to determine if your host supports .htaccess. If you are using IIS on a Windows server, you are out of luck. If your host uses Apache, there is a good chance they support .htaccess. It’s just that few publicize it. If in doubt, ask; or you can just upload one and try it. If it works, it’s supported; if it doesn’t work, it may not be supported.

What can .htaccess do?
Now that you’ve determined that your host supports .htaccess, what can you do with it? Well, to start, let’s look at the purpost of a .htaccess file. On an Apache server there is a configuration file that tells the server how to act. But, before that configuration is used, Apache looks to the subdirectory that the requested file is in and all it’s parents for a .htaccess file. If a .htaccess file is found it can override certain settings.

So, with that said, what can I do with it?

  • Custom Error Pages
  • Deny or Allow users based on IP address
  • Not allowing browsing of directories
  • Redirect users
  • Using a file other than index.html

So, how do I create a .htaccess file?
A .htaccess file is simply a text file, so any program capable of saving in plain text can be used. The biggest snag that you will hit is that Windows doesn’t like the file name. Windows based machines see .htaccess as a file extension without a name. The 32-bit Windows versions can handle it with long file name support, but older versions can not.

To create your own, Notepad is probably the easiest method. Create a new file, enter your directives, and save it as .htaccess. Upload the file to the root of your website. Done. Worst case, nothing happens if it doesn’t work.

As an aside, the period on the front of the filename causes Unix / Linux based systems to treat it as a hidden file.

Pages: 1 2 3 4 5

Leave a Reply

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