By David Callan
You may have already come across the .htaccess file while on www.akamarketing.com, we used it in the article Custom error pages to enable you to set up custom error pages so visitors will be taken to a custom error page on your site and not your hosts error page or what's even worse the default page not found type of error page.
Laptop Battery Using the .htacces file for custom error pages is however only the tip of the iceberg, the file can be used in a lot more ways but before we go into the nitty gritty of what can be done with it lets first explain what it is and where it is found.
In addition to these three files, directory basis by using .htaccess files in directories accessed by the server.
Thinkpad The .htaccess file is a file that enables you to control how your hosts server deals with your website and webpages. This usually involves adding lines of code to the file or editing lines already present. You should be aware that editing the .htaccess file can seriously alter your website and webpages so always make a copy of the original and store it in a safe place so if anything does go wrong you can easily revert back to the old file.
Editing .htaccess Before letting you know how to edit a .htaccess file, it is important to define what .htacess is and the purpose it serves. .htaccess is a file extension, not a file. An htacess file is simply a text file in ASCII mode, containing Apache directives provided by the Apache web servers to execute commands for controlling a website. Creating a file with .htacess extension is very easy – open up a text editor like Notepad or SimpleText, write the command and save that page as .htaccess.
Microsoft As for the location of the file, the file is usually found in the root directory of your website, if it's not there don't worry as it can be easily created. Simply open a blank text document and call it .htaccess and then upload it. Even if you use an online manager instead of an FTP program the process is still similar, just select new file and call it .htaccess.
Bullet back to top Edit a .htacess file with any text editing software Any text editing software is sufficient to create or modify the .htaccess files; thumb being to keep all the commands in a .htaccess file placed on a single line. This can be achieved by disabling the wrap feature of the text editor. In case the text editor or the operating system does not allow saving files with the .htaccess extension, the alternative is to save the file as .htaccess.txt before uploading it to the server. At certain times, it is also needed to CHMOD the htaccess file to 644 or ( - -). for making the file usable by the server and to prevent it from being read by a browser. The FTP client should be used then for renaming the file to its proper name (.htaccess). It is also advised to upload the .htaccess files in ASCII mode, and not in BINARY. To hide the inner content of the file,
Laptop Computers You can if you want upload two or more different .htaccess files to two or more different directories, each file will affect the directory it's in but will not overwrite .htaccess files that are in other directories. This means that a .htaccess file will affect all sub-directories unless that sub-directory has its own .htaccess file. This property of .htaccess files is useful for example if you wanted to set a directory's default page to something other than index.html and have different default pages for all sub-directories too, but more on that later.
/* In case you want to override the servers settings regarding stopping of unauthorized access, write the following in the command line of your .htaccess file. Options +Indexes Allowing SSI in .html files Servers, mostly analyze syntactically (parse) files with a .shtml extension for Server Side Includes (SSI). In case this extension needs to be excluded or if it becomes a priority to retain the .htm or .html extensions used by files prior to a change, adding the following commands to .htaccess file can solve the problem.
Laptop Computer Now we'll go through some of the more useful things that can be done with the .htaccess file, we'll also tell you how to do these things. Well first we have the custom error page feature, if you want to learn about this check out my article entitled Custom error pages.
The phrase ``By Invitation Only'' up box, where the user will have to type their credentials. You will need to restart your Apache server in order for the new configuration to take effect, if these directives were put in the main server configuration file. Directives placed in .htaccess files take effect immediately, since .htaccess files are parsed each time files are served.
Desktop Computer File protection is also another use of the .htaccess file. This enables you to protect certain directories and files by way of a username and password. We used to use it here at www.akamarketing.com for our free ebook directory which in the past required that you be a member of the AKA Marketing webmaster community before being given access to the directory.
Notebooks It involves placing a small file in the directory you want to protect. It's very easy to implement, here's how it's done. Before we start you need to be able to Telnet your site. If Telnet is not available then you should look into a CGI script to protect your files.
Lenovo This is what should be in the .htaccess file
Hard Drive AuthUserFile /usr/www/dirname/.htpasswd
AuthGroupFile /dev/null
AuthName "The ebook directory"
AuthType Basic
Travelstar
require valid-user
Gateway You only need to change two of the above lines. Change the AuthUserFile line so that the UNIX PATH matches that of your system. This is where the password file will reside.
Laptop Parts AuthName is the name of the thing your protecting, the popup box in this case would say 'Enter your password for The ebook directory', you of course should change this to something which correspondents to the section of your site which your trying to protect.
Software Using Telnet go to the directory your AuthUserFile path is pointing to and type 'htpasswd -c .htpasswd username' to create the file and add "username" as the first user. The program will prompt you for a password then verify it by asking again. You'll not see the password when entering it so be extra careful.
Hard Drives htpasswd -c .htpasswd username is only used to create the initial .htpasswd file, after the first username and password is entered you've to type in 'htpasswd .htpasswd Jack' leaving out the '-c'. The above code would add the username Jack to your .htpasswd file and again you'll be asked to input a password.
Electronics To delete usernames you'd simply open up the .htpasswd file and remove the appropriate lines.
Canon If you want to discontinue the protection of a directory simply type the command 'rm .htaccess'
Desktop Pc If you haven't got a Telnet client you can get the puTTy client for free here!
Desktop Computers The next thing we can do with the .htaccess file is change the default page from index.html to one of your choosing.
Think Pad By default most web servers will load index.html as the default page, some webmasters will not want this on all occasions. I myself wanted a CGI script as the default page for one of my directories to enable a short address to go in my signature file.
Repair I changed the default file in the sub-directory 'webmaster-forums' to ikonboard.cgi so the forum address would be akamarketing.com/webmaster-forums and not akamarketing.com/
webmaster-forums/ikonboard.cgi which is longer and harder to remember. Here's how it's done.
Data Recovery Simply insert the line
DirectoryIndex ikonboard.cgi index.html
Cisco I placed this code in the .htaccess file in my webmaster-forums sub-directory, this means that when the webmaster-forums folder is requested the server will load ikonboard.cgi first and if that's not found it will load index.html.
Keyboard I left my main directory unchanged so the root directory's default page is still index.html. You of course would change ikonboard.cgi to the file you want to load first, maybe index.cgi, index.php or home.html, basically any file a browser can handle. That was easy wasn't it?
Monitor Well that's it then. As you can see the .htaccess can be set up to do some very useful things for the webmaster. We've covered three of these in this article, these where custom errors, password protection and setting the default file to something other than index.html.
Desktop There are however other uses of the .htaccess file including using it to restrict access from certain domains/IP's and using it to prevent people from stealing your bandwidth, but to be quite honest I don't really understand these two myself so I'm not going to try and teach you something I don't understand.
Infosys If you want to learn more about the .htaccess file do a search for it on Google, you'll be returned with lots of good sites you can check out.
Refurbished Laptops
Wipro Article by David Callan. David is an Internet marketing professional and webmaster of http://www.akamarketing.com/webmaster-forums/ webmaster forums. Visit his webmaster forums for the latest discussions on search engines, website authoring and Internet marketing related issues and topics.
[ Comment, Edit or Article Submission ]