Simply speaking, .htaccess is a configuration file that can alter Apache server’s behavior. But this simple definition overlooks most of its capabilities hence a moderate level of analysis is needed.
Suppose, your project directory structure deployed in a server is as follows:
You have written a bunch of directives in an .htaccess file to be applied on all .php files under modules directory. The .htaccess file is placed in modules directory, but its effect will reflect on all .php files in modules as well as all php files in subdirectories under modules.
For example, many web hosting companies provide shared hosting plan. If you are a developer/blogger playing with this, you already know they do not allow their customers to access the global configuration file directly as it may affect other customers hosted on that server. Instead, they provide a mean to configure Apache server for their own directories and subdirectories through .htaccsess.
Note: “Directives” are commands or instructions used for modifying Apache server’s behavior.
An .htaccess offers a bunch of powerful features & functionalities that we can exploit several ways. These are great tools for developers as well as bloggers. It allows developers to execute a bunch of directives without requiring access to Apache’s core server configuration file.
Creating .htaccess file is very simple. You can create it using Notepad, Notepad++ , Netbeans IDE keeping the only thing in mind to name the file .httacess without any other extension. Simply open Notepad and save the file as .htaccess. Once you are done you can upload it to server using ftp client like FileZilla.
The placement of the .htaccess file is important as its effect may vary based on where it is placed. The file can be placed in any directory or subdirectory for which changing configuration is needed. If .htaccess file is placed in root directory, it will affect that directory as well as its subdirectories. On the other hand, if .htaccess file is placed in subdirectory it will affect the subdirectory, side by side override directives or commands of .htaccess files placed in higher ups.
By default, almost all hosting companies allow their customers to execute directives in .htaccess file on their servers, so nothing to worry about this. But, if you need to configure .htaccess on your local server you have enable mod_rewrite extension in php.ini file in Apache Web Server configurations.
Simply a lot, I am listing a few of that
And so on.
As name implies, rewrite rules are rules rewritten for overriding existing rules. The ability to rewrite urls is one of the powerful features of .htaccess that enables us to manipulate urls, transforming some long ugly URLs into clean SEO friendly URLs.
http:// yoursite.com/home RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?param=$1
Step1: check whether mod_rewrite module is on
Step 2: You only need to do this once per .htaccess file to turn rewrite engine on
Step 3: Write your rewrite rule
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?param=$1 [NC,L]
<IfModule mod_rewrite.c> Options +FollowSymlinks
RewriteEngine on RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?param=$1 [NC,L] </IfModule>
NOTE: Apache recommends to use .htaccess when