W3-Video WEB Tutorials

w3-video.com is a Free eLearning Website with over 500 video tutorials on HTML5, XAMPP, .htaccess, Firefox, Notepad++

.htaccess Tutorial

Home HTML5 XAMPP .htaccess Firefox Notepad++


5. Conditions to met for .htaccess to work, Tutorial


Share it

.htaccess works if:

Overriding configuration directives per directory level through .htaccess file is only possible IF:

  1. check the Apache version
    • Apache version 2.2
  2. .htaccess file is enabled
    • AccessFileName .htaccess
  3. the directives you want to use, can be overriden through .htaccess
    • AllowOverride All
    • or specify the grouping of directives needed e.g. AllowOverride FileInfo
  4. the module that provides that directive is enabled
    • e.g. LoadModule rewrite_module modules/mod_rewrite.so
    • check loaded modules on server phpinfo();
  5. the .htaccess file contains valid directives, syntax respected
    • corresponding valid directives added in .htaccess
  6. 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. Checking Apache's version
1Apache/2.2.21
2. htaccess enabled (httpd-default.conf)
1AccessFileName .htaccess
3. AllowOverride All or the corresponding grouping of directives (httpd.conf)
1

2
AllowOverride All
or
AllowOverride Indexes
4. mod_dir module loaded (httpd.conf)
1LoadModule dir_module modules/mod_dir.so
5. add and save valid directive in .htaccess ⁄ .htaccess syntax respected
1DirectoryIndex index.php index.html x.txt
6. upload the .htaccess file on server (desired directory)
.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 htaccess file, please see the spec: apache.org