Fri, Mar 19 2010 - 09:23:55 (UTC)

rssHome » Non e-Book » .htaccess

.htaccess files and mod_rewrite

Contents

  1. Introduction to .htaccess files
  2. FileTypes
  3. Handlers
  4. URL Rewriting
  5. User authentication
  6. Host-based access control
  7. Directory indexing

Introduction to .htaccess files

Your Web directory and its subdirectories can contain per-directory configuration files called .htaccess files. Whenever Stronghold (our Web server) receives a request for a file, it first looks for a file called .htaccess in that directory and its parent directories. If one is present, Stronghold considers the configuration directives within it before responding to the request. A .htaccess file works like this:

  • A .htaccess file must be a plain text file and contain no special formatting elements. Use a text editor to create your .htaccess file. If you create it with a word processor, be sure to save it as plain text.
  • A .htaccess file contains a list of configuration directives and nothing else.
  • If a .htaccess file contains any other information, it must be commented out in order to prevent errors
  • A .htaccess file must be saved in the top directory to which you want it to apply. The directives apply to that directory and its subdirectories.
  • If a subdirectory contains a .htaccess file, it overrides the .htaccess files of its parent directories.
  • The directives themselves should occupy one line each, like this:
    ErrorDocument 404 errors/404.html
    LanguagePriority en fr jp de
    CookieTracking off
    phpShowInfo on
    FancyIndexing on
    HeaderName header.html
    ReadmeName readme.html
    XBitHack full


Some valid .htaccess configuration directives are listed in the next sections. There are several types of configuration directives that control different server features.

Complete guide to .htaccess for Beginner

Complete guide to .htaccess for BeginnerTutorial Introduction


Tutorial written and contributed by Feyd, moderator of the JK Forum and JavascriptKit. Please see tutorial footnote for additional/bio info on author.

I am sure that most of you have heard of htaccess, if just vaguely, and that you may think you have a fair idea of what can be done with an htaccess file. You are more than likely mistaken about that, however. Regardless, even if you have never heard of htaccess and what it can do for you, the intention of this tutorial is to get you two moving along nicely together.

If you have heard of htaccess, chances are that it has been in relation to implementing custom error pages or password protected directories. But there is much more available to you through the marvelously simple .htaccess file.

Contents

  1. Tutorial Introduction
  2. Error Documents
  3. Password protection
  4. Enabling SSI via htaccess
  5. Blocking users by IP
  6. Blocking users/ sites by referrer
  7. Blocking bad bots and site rippers (aka offline browsers)
  8. Change your default directory page
  9. Redirects
  10. Prevent viewing of htaccess
  11. Adding MIME types
  12. Preventing hot linking of your images and other file types
  13. Preventing directory listing
  14. Conclusion and more information

Continue Reading »