5. Conditions to met for .htaccess to work, Tutorial
.htaccess works if:
Overriding configuration directives per directory level through .htaccess file is only possible IF:
- check the Apache version
- Apache version 2.2
- .htaccess file is enabled
- AccessFileName .htaccess
- the directives you want to use, can be overriden through .htaccess
- AllowOverride All
- or specify the grouping of directives needed e.g. AllowOverride FileInfo
- the module that provides that directive is enabled
- e.g. LoadModule rewrite_module modules/mod_rewrite.so
- check loaded modules on server phpinfo();
- the .htaccess file contains valid directives, syntax respected
- corresponding valid directives added in .htaccess
- the .htaccess file is on server within the desired directory
- upload .htaccess on server
.htaccess conditions Examples
1. Apache version | 2. htaccess enabled | 3. AllowOverride | 4. module loaded | 5. valid directive in .htaccess | 6. .htaccess on server
Example: Set index page requires
1 | Apache/2.2.21 |
1 | AccessFileName .htaccess |
1 2 | AllowOverride All or AllowOverride Indexes |
1 | LoadModule dir_module modules/mod_dir.so |
1 | DirectoryIndex index.php index.html x.txt |
.htaccess on server |
Video demonstration .htaccess file works (PART I)
.htaccess file works if, Tutorial
min | video details |
---|---|
00:01 | Conditions to met for .htaccess to work Tutorial |
00:06 | Overriding configuration directives per directory level through .htaccess file is only possible IF |
00:12 | 1. checking the Apache version: Apache version is important: from one version to another, the Apache documentation undergoes significant changes |
00:21 | 'lol' is not a valid directive → server error (one fast way to check the version)Apache version 2.2.21 |
00:38 | 2. checking if .htaccess is enabled: AccessFileName: .htaccess |
00:58 | in a shared hosting environment you can't access server configuration files, but BY DEFAULT, the AccessFileName is .htaccess |
01:07 | 3. AllowOverride directives If the value/argument is 'All' (AllowOverride All) → any directive within this LIST can be overriden through .htaccess |
01:48 | click here to see the AllowOverride tutorial |
01:54 | in a shared hosting environment you don't have access to the httpd.conf file. If a directive doesn't work while all other conditions are met, then the directive can't be overriden. Contact your hosting company. |
Video demonstration .htaccess file works (PART II)
.htaccess file works if, Tutorial
02:01 | 4. check if module loaded the module that provides that directive must be enabled for the directive to worke.g. DirectoryIndex directive /mod_dir |
02:25 | in a shared hosting environment you don't have access to the httpd.conf file but you can check the list of loaded modules using a simple php function like this: |
02:43 | upload the .php file on server |
03:03 | mod_dir module Loaded |
03:14 | 5. valid directive(s) in .htaccess /.htaccess syntax respected |
03:38 | Testing the DirectoryIndex directive ⁄ .htaccessindex.php delivered by default |
03:48 | index.html delivered by default |
04:02 | x.txt delivered by default |
04:04 | .htaccess' directive works |
04:10 | 6. .htaccess uploaded on serverwithin the root directory: htdocs /XAMPP public_html/shared hosting environment |
For more information about the apache.org
file, please see the spec: