The sheer htaccess power
If your website runs on an Apache server, you can use htaccess to solve some common webmaster problems.Many webmasters underestimate the htaccess possibilities or aren't even aware of them.
Let's try to change this here and see, if we can keep it as simple as possible, so that every webmaster, experienced or newbie, can use htaccess successfully.
Instead of giving the htaccess file a name and an extension, like 'textfile.txt', it only has an extension: .htaccess
The full stop in front of htaccess is required.
I'm going to describe some basic htaccess options here that will solve many webmaster problems in a snap. Master them first and then search the web for more complicated applications.
- When you develop your website, you will undoubtedly end up with 'old' pages that you don't use anymore. But they still are listed in the search engines. Taking them down would be a waste of traffic. And search engines don't like a redirect in your Meta Tags (because of abuse). Here's a simple htaccess option to permanently redirect from old pages to new ones.
- You want to password protect a certain area on your site. You can do so using htaccess in combination with .htpassword.
- Recognize these ugly pages saying: "404 Page Not Found"? Here's an htaccess error page solution that keeps your visitors on your site.
- Sometimes you may want to block someone from gaining access to your site, eg a spammer or a stalker. It's very easy to block an IP using htaccess.
- If someone uses a URL that points to a directory, like www.anownsite.com/, a default page will load. That can be index.html or default.html or anything that loads by default. If you want something else to show up by default, you can easily do so by using by using default directory page with htaccess.
Try them, implement and test them. If that taste like more, search the net for .htaccess. You will find tons of resources.
Some important remarks about the htaccess file
- Always download your latest htaccess file to your hard drive to see what's on it! You see, many websites can be maintained by a shell like Cpanel. If you use that, for instance, to deny access to a certain IP address, Cpanel will write a line of code to your htaccess file. If you didn't download the latest version and leave that line in there, you could easily overwrite any lines added by Cpanel.
- In general, if you're not experienced yet, it's a good idea to leave anything in the htaccess file once downloaded (unless you know what you're doing of course). You can simply add new commands at the bottom of the existing file. But for maintenance reasons, keep similar lines together. It makes it easier to read the htaccess file.
- Since this is a text file, you will always need to upload it to your server in ASCII mode.
- Furthermore, for security reasons, you need to CHMOD the htaccess file to 644 (RW-R--R--) so that your Apache server can read it, but browsers can't. Otherwise your security could be seriously compromised.
