PHP, MySQL, Drupal, .htaccess, Robots.txt, Phponwebsites: REQUEST_FILENAME
REQUEST_FILENAME - phponwebsites.com
Showing posts with label REQUEST_FILENAME. Show all posts

14 Nov 2013

What is .htaccess

                       Hypertext  access is shortly called as htaccess. It is a directory level configuration file. Directory level means, where you locate your .htaccess file, it configure that directory only. Mostly, on server, it is placed on public_html folder for configure the files to access. You can control your site using it. It is supported by web servers.
   

Uses of .htaccess:


why we use .htaccess

           - DirectoryIndex uses
           - used for restrict the user for access pages from website
           - redirect the urls
           - gives direction to server rather than search engine
           - create error document
           - compressing resources with gzip
           - add expires headers
           - enable and disable the additional functionality of apache webserver
           - prevent access to php.ini file
           - force scripts to display as a source code
           - ensure media files are downloaded instead of played
     

How to start with .htaccess?


   Syntax:
         <IfModule mod_rewrite.c>
             RewriteEngine On
             RewriteCond  %(REQUEST_FILENAME) !-f
             RewriteCond  %(REQUEST_FILENAME) !-d
             RewriteCond  %(REQUEST_FILENAME) !-l
             RewriteBase /
             DirectoryIndex index.php
             RewriteRule ^home index.php [L]
         </IfModule>
  Explanation:
     <IfModule mod_rewrite.c>
                                IfModule test whether mod_rewrite.c is included in apache. If mod_rewrite.c
is included, then it run. Otherwise it doesn't get run.
     RewriteEngine On
                                It tells apache to turn on its RewriteRules.
     RewriteCond
                                RewriteCond execute the next rewrite rules if it is correct.
%(REQUEST_FILENAME) is a variable based on url you request
!-f, !-d, !-l are extension added to regular expression.
where,
         !- f - rewrite condition if it is not  file
         !-d - rewrite condition if it is not directory
         !-l  - rewrite condition if it is not link
 if a file, taken from variable %(REQUEST_FILENAME) does not exist on the file system, then return true.
        RewriteBase /
                              It provide base for RewriteRules.                  
        DirectoryIndex index.php
                              It tells apache to which file is run first when server access to particular directory.
        RewriteRule
                              It redirect the urls.
RewriteRule ^home index.php [L]
      it means, when url get ' home ' on address bar, it runs the file index.php. Using this method, we can change our address bar contents to anything.
          For example,
                 RewriteRule ^sample.html sample.php [L]
                 where,
                            you type sample.html in your address bar, the .htaccess runs sample.php file.
  we can pass the values in address bar using it.
     
Related Post: