News Ticker

Learn All About htaccess With Simple Examples

By Ajay Verma - Friday 13 November 2015 No Comments
Htaccess (HyperText Access) is a directory-level configuration file that allows developers and programmers to alter the configuration, supported by several web servers in order to provide additional functionality without alter in the server config files.
Htaccess Directory Level Configuration:
.htaccess file will affect the directory it is placed in and all resulting sub-directories (files and folder). Therefore, if we add ‘.htaccess’ file to the ‘home folder’ then it will affect all subsequent folders like so:
| -- dir1                                        Χ - not affected by htaccess
| -- dir2                                       √ - affected by htaccess
| | -- dir3/dir4                                 - affected by htaccess
| | -- dir5/file.php                            √ - affected by htaccess
| | -- .htaccess
| -- home.html                                  Χ - not affected by htaccess

Creating, Editing and Uploading an .htaccess File
to create htaccess file, open any text editor supported by your operating system write code and save the file as .htaccess, similarly to edit open file with text editor and you can modify code.
Use of .htaccess to set up Mod_Rewrite
Mod_Rewrite allows us to make custom and simplified URLs as needed.
for example some url most likely looked something like:

In reality, the actual URL may have looked closer to this:

Working of Mod_Rewrite
RewriteRule Pattern Substitution [OptionalFlags]
Example 1:
RewriteEngine on
RewriteRule ^whoami.php$ unknowndevice64.html

When User will visit (^-match the whole string) And will redirect to

Example 2:
RewriteEngine on
RewriteRule ^unknowndevice64/([A-Za-z0-9-]+)/?$ whoami.php?service=$1 [NC]

When User will visit,  (^-match the whole string) and
([A-Za-z0-9-]+) refers to any information that could be typed into the URL after /service/
+: The plus sign indicates a single character that is either a letter or a number.
/?$: points out the end of the string. The question mark allows the last character in the string to be a forward slash (although it does not require it).
results.php?products=$1: the $1 it will put in the information captured from whatever people wrote in the
"([A-Za-z0-9-]+):" part.
After the process completes, the browser will display the information from below URL

No Comment to " Learn All About htaccess With Simple Examples "