how to control request with htaccess

Tag: .htaccess Author: gavin0 Date: 2009-08-02
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]


I am a beginner in htaccess , so does any one help me to describe what is that lines means?

Best Answer

A little more in detail:

  • <IfModule mod_rewrite.c>
    The contents of a <IfModule> block are only processed if the condition is true. In this case the enclosed directives are only processed if the module mod_rewrite is loaded.

  • RewriteEngine On
    RewriteEngine On is needed to enable the rewriting engine for that directory and its subdirectories.

  • RewriteBase /
    RewriteBase / sets the per-directory base URL path to /. But this is only necessary if the URL path is not the physical path.

  • RewriteCond %{REQUEST_FILENAME} !-f
    This condition states that the requested filename (the requested URL path mapped to the file system) must not be a regular file.

  • RewriteCond %{REQUEST_FILENAME} !-d
    The same as the previous but it must not be an existing directory.

  • RewriteRule . /index.php [L]
    This rule will match any non empty URL path (more precisely: the requested URL path without the base URL path) and substitutes it with /index.php if the corresponding conditions both are true. Additionally it is flagged as the last rule, so when the rule is applied, the current rule processing will stop here.

  • </IfModule>
    Counterpart to <IfModule …>.


This is what am looking ,, thank u

Other Answer1

The .htaccess is rewriting all requests except for directories and physical files that exist in the rewrite base (the directory where this .htaccess lives, it looks like) to /index.php. This is a fairly standard practice with many Frameworks and Content Management Systems to achieve the "pretty" URLs (such as you see with Stack Overflow).

You might be interested in the mod_rewrite docs, also.