Blogs

Less is More...

less, the GNU utility that resembles the classic UNIX more command, has capabilities you might not be aware of. Sure, it will page through files, but have you ever tried the following?

  less somefile.tar.gz
  less somefile.tar.bz2
  less somefile.zip
  less somepackage.rpm

These commands are equivalent to the following, respectively:

  tar ztvf somefile.tar.gz | less
  tar jtvf somefile.tar.bz2 | less
  unzip -l somefile.zip | less
  (rpm -qpi somepackage.rpm; rpm -qpl somepackage.rpm) | less

.htaccess, a primer...

The Apache web server has a number of configuration options that are available to the server administrator. In a shared hosting environment, you don't have access to the main Apache configuration so you're stuck with the default configuration. However, it is possible to override some of the default settings by creating (or editing) a file named ".htaccess".

The .htaccess is a simple ASCII text file placed in your www directory or in a subdirectory of your www directory. You can create or edit this file in any text editor (such as NotePad) and then upload it to the directory for which you want to modify the settings. Be sure that the file is uploaded in ASCII (not BINARY) format, and be sure that the file permissions for the file are set to 644 (rw-r--r--). This allows the server to access the file, but prevents visitors from accessing the file through their web browser (a security risk.)

Commands in the .htaccess file affect the directory that it's placed in and all subdirectories. If you place the .htaccess file in your www directory, it will affect your entire web site. If you place it in a subdirectory of your www directory, it will affect only that directory plus and subdirectories of that directory.

Most .htaccess commands are designed to be placed on one line. If your text editor wraps lines automatically, you should disable that function before saving and uploading your file. Also, note that .htaccess commands are case-sensitive.


The information presented here may work and it may not, or it may work today and not tomorrow. Use it at your own risk.

Some of the things you can do with .htaccess include:

Customize Error Messages

If you want to override the server's error pages, you can use .htaccess to define your own messages. An example of the syntax is:

ErrorDocument 500 /error.html

Override SSI Settings

By default, only pages ending in the .shtml extension will parse server-side includes (SSI). You can override this restriction in your .htaccess file:

If you want to override the default server configuration so that SSI will work with .html documents, you can create a file named .htaccess and upload it (in ASCII mode) to your main www directory. Add the following lines to your .htaccess file:

AddType text/html .html
AddHandler server-parsed .html

If you want both .html and .htm documents to parse SSI, create your .htaccess file with these lines:

AddType text/html .html
AddHandler server-parsed .html
AddHandler server-parsed .htm

Change Your Default Home Page

In order to browse your site by specifying the domain name only (e.g., http://www.yourdomain.com) instead of having to specify an exact page filename (e.g., http://www.yourdomain.com/filename.html), you must have an index page in your www directory. Default acceptable file names for index pages include index.htm, index.html, index.cgi, index.shtml, index.php, etc. Note that they're all named index.*.

There is also a default order of precedence for these names. So if you have both a file named index.cgi and a file named index.html in your directory, the server will display index.cgi because that name takes a higher precedence than index.html.

Using .htaccess, you can define additional index filenames and/or change the order of precedence. To define your index page as custom.html add the following line to your .htaccess file:

DirectoryIndex custom.html

This will cause the server to look for a file named custom.html. If it finds that file, it will display it. If it does not find that file, it will return a 404 Missing Page error.

To change the order of precedence, enter a DirectoryIndex command with multiple file names on the same line. The order in which the file names are listed (from left to right) determines the order of precedence. For example,

DirectoryIndex custom.html index.cgi index.php index.html

Enable Directory Browsing

This is the option that allows the contents of a directory to be displayed in the browser when the directory does not contain an index page.

For example, if you make an http call to a directory such as http://yourdomain.com/images/, it would list all the images in that directory without the need for an html page with links.

If you require this option on specific directories it is still available. You can reactivate it by adding the following line to your .htaccess file:

    
Options +Indexes

Once this is added, the directory will fully index again. (Note: Coversely "Options -Indexes" will prevent directory browsing.)

Preventing Directory Listing

Do you have a directory full of images or zips that you do not want people to be able to browse through? Typically a server is setup to prevent directory listing, but sometimes they are not. If not, become self-sufficient and fix it yourself:

Web page redirection...

Want a way to automatically redirect your visitors to a new location? It's easier than you think if you use the META tag.

META tags are a powerful but often poorly understand part of HTML. The tag was created to allow webmasters to specify important "meta data" about their document. What's meta data? Literally, it's data about data. A META tag contains information about your overall Web page that's important for indexing, archiving, or otherwise managing the page. Think of it as the librarian's favorite tag.

By far the most frequent use of META tags is to help search engines index your page. By using a META tag with keywords or a document description, you can dramatically boost your ranking in the major search engines. Description and keyword versions of the META tag look like this:

Syndicate content
Comment