A simple guide to .htaccess
What is .htaccess
The .htaccess file is a simple text file (in ASCII format). In general you can use, .htaccess files to change some configuration directives of the apache web server. However, .htaccess files can do lot more than simply change some settings of your web server as you will find from the topics listed in this tutorial.
Please, note that the name of the file is “.htaccess”. It starts with a dot. By default on Unix/Linux systems files starting with a dot are not publicly visible. If you are running a Windows PC, it is likely that you will have troubles creating such a file. So if you need to create such a file, create it directly on your web hosting server and modify it there, using your FTP program, SSH or some web based file manager.
The .htaccess file can be placed on any folder on your site. It has recursive effect. This means that if you place the .htaccess file in your web root (the main folder of your web site) the directives and commands you place in the .htaccess file will have effect on all sub-folders.
If you place a .htaccess file in a sub-folder, its directives will override the ones that you have in your site main folder. That is if you disable directory listing globally for your site by placing the proper line in the .htaccess file in your main folder, you can then enable directory listing only for a particular sub-folder with another .htaccess file and the proper directive.
The commands and/or directives in a .htaccess file are placed one at a line.
You can comment a given line in a .htaccess file using the hash symbol “#”. For example:
When a line is commented it has no effect.
When somebody visits your site the Apache web server is checking if you have an .htaccess file somewhere in your web space starting from the root/main folder and traversing all the folders until it reaches the requested file. If an .htaccess file is found, its directives are applied to the current request.
It is important to know that the .htaccess file should be readable by the Apache server. So, please check with your host if they require any special permission set for .htaccess files. In general permissions of 644 should be working just fine.
- How to block users from accessing your site based on their IP address
- How to prevent or allow directory listing?
- How to change the error documents – 404 Page Not Found, etc
- Using .htaccess for password protecting your folders
- Using .htaccess to block referrer spam
- Disable Hot-Linking of images and other files
- Redirect URLs using .htaccess
- Introduction to mod_rewrite and some basic examples
- Force SSL/https using .htaccess and mod_rewrite
- 301 Permanent redirects for parked domain names
- Enable CGI, SSI with .htaccess
- How to add Mime-Types using .htaccess
- Change default directory page
- Block Bad robots, spiders, crawlers and harvesters
- Make PHP to work in your HTML files with .htacess
- Change PHP variables using .htaccess
- HTTP Authentication with PHP running as CGI/SuExec
- Force www vs non-www to avoid duplicate content on Google
- Duplicate content fix index.html vs / (slash only)
Comments 40 >>
|Previous: The effects of a Gated Internet on small business and the web hosting industry||Next: Overselling Tendency In The Hosting Market|
Back to Web Hosting Articles list