Enable Redirect mod in apache2

When you are doing something with .htaccess , then you have verify the redirect mod is enabled. By

$cd /etc/apache2/mods-enabled/


check name like “rewrite.mod“. If it is not there then type

$sudo  a2enmod rewrite

Now you can see the rewrite mod is enabled in /ect/apache2/mods-enabled/.

*$sudo  /etc/init.d/apache2 restart


Today tried redirecting and rewriting for URL . For this we need to create a .htaccess file in site root directory for web application folder.

This is my sample code(inside .htaccess file)

RewriteEngine On

RewriteRule ^a/([^/]+)/([^/]+) /index.php?q=$1&t=$2 [L,QSA,NC]

If my URL is like this , http://sample.com/a/one/two
Then the rule will redirect as http://sample.com/index.php?q=one&t=two

In index.php file we access the values by $_REQUEST[‘one’] and  $_REQUEST[‘two’].

We can do more then these rewrite rules.

Ref: http://corz.org/serv/tricks/htaccess2.php