Sunday, October 11, 2009

Htaccess tutorial for beginners

Note: Before using this you have to take backup for that code, I am not responsible for any problem occurred to your site.

I am explaining this by an example:
First create a folder name as Htest
In that folder create three files one is Test.php, First.php, .Htaccess

Test.php
Test
Click Test Page(href="http://sitename/some.php")

First.php
First
Click First Page(href="http://sitename/second.php")

.Htaccess
RewriteEngine On
RewriteRule ^(second.php)$ ./Test.php [L]
RewriteRule ^(some.php)$ ./First.php [L]

In the above example if you execute Test.php file and click on the link it goes to First.php page but in url it shows second.php because of first line in RewriteRule ^(some.php)$ ./First.php [L]
In .htaccess file as well as same process happen when executes First.php

If you have good idea about regular expressions you can do better.