There are many tools of the trade in theworld of Web site development, but very few have as many good uses asyour .htaccess file. What, you don't have one? I'll admit, informationon these little darlings are confusing to some and hard to find. Hencethe reason why we need an explanation of what it is and what it can dofor you.Inside your Web hosting space, you know you have folders, HTMLdocuments, and other things that make your Web site work. Think of thisfile as just another addition to the many thing you have inside there.It usually sits inside your root directory, such as "/public_html/" andhas more than a few good uses. You might already have a .htaccess filein your root directory. If so, all you need to do is edit that one.Just remember that if it is in your root directory, that it will effectall folders and documents inside that directory. If you want to override that, then you will have to make a new .htaccess file inside thedirectory in question.
For an example, if you want what is in the .htaccess file to effecteverything but your "photos" folder then you would have to create a new.htaccess file inside your "photos" folder.
How can you create one? Well, depending on the FTP program you areusing it should be as easy as creating a new document, then renaming it.htaccess. Note that it has nothing coming before the dot. If you haveanything in front of the dot, then it will not be read by the Webhosting server as a .htaccess file. The server will not know what to dowith it.
If you want to create the file on your computer first, you should beable to right-click your desktop and select "New" then "Text Document".Then right-click that document on your desktop, and go to "Rename".Type in the new name as ".htaccess". Some programs might put the .txtextension on it automatically. All you have to do is go in to rename itagain, and take that part off.
Another thing to remember is if you are creating the file on yourown computer or uploading it from your own computer, make sure you areuploading it in ASCII mode, not binary. Most FTP programs do a prettygood job at auto-detecting how it should be uploaded, but if you runinto a problem that is the first place I would check.
Also, .htaccess files can only be created on a Linux based serverrunning Apache. If you are not sure if you fall into that categorylogin to your control panel your Web host provided you and snoop aroundin there. If you are still not sure, feel free to ask your Web host.That is what they are there for! You may need to CHMOD the htaccessfile to 644 so the sever can execute the commands inside it.
Now you know how to create an empty .htaccess file. Now it is time tostart filling it up with some easy to learn and useful commands. Thinkof each line you put into the .htaccess file as a command for the Webhosting server to do something. Here is an example of what I mean.Think of this as the content of your .htaccess file:
- Take out the trash
- Clean the sink
- Mow the yard
- Rake the leaves
Each are short commands you might do during your own day. A.htaccess file is much like giving the Web hosting server a to do list.Most commands in the .htaccess file are suppose to be on one line only.This is just the way that the server reads the information.
Another warning you might take in consideration is the ability to usethe .htaccess file at all. Some Web hosts have banned it or banned itfor certain uses because it causes stress and strain on the Web hostingserver itself. Make sure you read through your Web host's frequentlyasked questions and acceptable use policy before moving forward. Ifthey have something against it, then it should be in one of those twoplaces.
Now that you have it, what can you do with it? That is another fewarticles all together. Some of the coolest things are passwordprotection, error page redirects, and deny/allow IP address to accessyour Web site.
Related Articles
- Introduction to .htaccess.htaccess is a Unix/Linux based file for Apache web servers that allow you to change access permissions and many other things for files on your web server.
To make a .htaccess file, open up an html editor, preferably notepad, and enter your commands(each on a seperate line). When saving your file... - No Direct LinkingIf you want to prevent those awful direct linkers, use this tutorial. Open up your notepad (start>>programs>>accessories>>notepad) or another text editor, and copy the code below to it. Name this file .htaccess and make sure it doesnt have an extension on the end, like .txt. If i....
- Change Default Directory PageA directorys defauly page is usually index.html, index.htm, or index.php. Therefore, when a visitors goes to www.domain.com they are automatically redirected to www.domain.com/index.html.
With .htaccess the default directory page can be changed.
Open your .htaccess file or create a new one. .... - Password ProtectionAlthough there are many uses for a .htaccess file, by far the most popular, and probably most useful, is being able to reliably password protect directories on websites. Although JavaScript can also be used to do this, only .htaccess has total security, because someone must know the password to get ...
- IP Banning1. Make a new text file and name it .htaccess or open one you already have.
2. Find out the persons IP address and substitute it for 000.000.000.000.
To deny access..
deny from 000.000.000.000
To allow access..
allow from 000.000.000.000
To ban everyone..
deny from all
To add mor.... - Prevent Directory ListingWhenever you have folders with large amounts of files or important administration files, it is essential to prevent directory listings, otherwise all of the files in the folder will be listed to anyone who wants to see them, including hackers. When hackers can find an administration file, it makes t...
- The Secret Of Custom Error PagesJust about every website has a broken link here or there that no longer connects to the page specified in the URL. These broken links loose you visitors and cost you money. Often what happens is you delete or move a page, and then forget to update some of the other pages on your site that lin...
- More Than One Way to RedirectAfter my article describing what a .htaccess file is and how it can be used to help your own Web development, I received dozens of E-mails on the subject. It has been one of the most popular topics I have covered for 2005 so far...
- RedirectionHave you changed the navigation structure of your website by moving or deleting pages of your site? If a visitor has the old page bookmarked or comes from a link on another site to it, they will receive a 404 error; page can not be found. Solve this by redirecting the visitor to the new page. The me...
- Introduction to HtaccessWhat is
