Tuesday, 8 May 2012

How to Impliment the Htaccess in your site...

At first before start proceedings we must know what is ht-access file and why we should use that one?

Basic Definition:
.htaccess files are configuration files of Apache Server which provide a way to make configuration changes on a per-directory basis. A file containing one or more configuration directives is placed in a particular document directory and the directives apply to that directory and all sub directories thereof.

per-directory basis: this means we have to put a ht-access file each directory of our web.

Example:
suppose we have 2 directories in our website like 

http://oms-vision.blogspot.in/(Parent Directory )
http://oms-vision.blogspot.in/admin(Child Directory)

the first one contains the files for http://oms-vision.blogspot.in/ and the second on contains its admin account files.now if we put a htaccess file in parent directory by having some rules

RewriteEngine On

order allow,deny
allow from all
RewriteRule  ^([a-zA-Z0-9_-]+)/$  index.php?action=$1  [NC]
RewriteRule  ^([a-zA-Z0-9_-]+)$  index.php?action=$1  [NC]
RewriteRule  ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$  index.php?action=$1&id=$2  [NC]
RewriteRule  ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$  index.php?action=$1&id=$2  [NC]
 


 then the same rules will be applied to its child directories also. 
now if u don't want to have any htaccess rules in child directory then u have to put another .htaccess file in child directory having rule


RewriteEngine Off


 
 

Monday, 7 May 2012

How To Enable mod_rewrite In LAMP- Ubuntu Linux

  • give permissions to the /var/www/ directory
           sudo chown -R $USER:$USER /var/www/
  •  Install the Apache module mod_rewrite
           a2enmod rewrite
  • Chnage the directory and keep the back up of the file “000-default”
          cd /etc/apache2/sites-enabled/
         sudo cp  000-default 000-default1
  • Edit the file 000-default
          sudo vi 000-default
          Look for the below given code
          Options Indexes FollowSymLinks MultiViews
          AllowOverride none
          Order allow,deny
          allow from all
          Modify “AllowOverride none” to “AllowOverride All”
  • Restart Apache
         sudo /etc/init.d/apache2 restart