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:
http://homefolder.com
| -- 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:
http://unknowndevice64.info/whoami/unknowndevice64

In reality, the actual URL may have looked closer to this:
http://unknowndevice64.info/Page.php?ID=ud64

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

Explanation:
When User will visit http://unknowndevice64.info/whoami.php (^-match the whole string) And will redirect to http://unknowndevice64.info/unknowndevice64.html

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

Explanation:
When User will visit http://unknowndevice64.info/service/security,  (^-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
http://unknowndevice64.info/whoami.php?service=security

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