Do you know how this URL was created: http://twitter.com/talksomething well a magic was used on the Apache to clean up the URL in more simple way. We call it .htaccess (in Linux) and htaccess.txt (in windows). This htaccess contains some instruction to how Apache must work. Initially first Apache searches for this htaccess file and then continue to load your page or what ever.
Today i will be showing you few ways where in you can create a smart URL that is SEO friendly and also User friendly
1. To rewrite from www.example.com/username.php?user=raghu to www.example.com/raghu
create a .htaccess file (for Linux) or htaccess.txt (for windows) in your project directory i.e there must be username.php present in the same directory
Now put this code:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ username.php?user=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ username.php?user=$1
And when you type the URL as www.example.com/raghu it will go to the user page but actually the long URL will be masked.
2. Hide current extension and add your own
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.asp$ $1.php [nc]
This converts all .php files to .asp virtually and it wont change the extension of the files.
So when you tap in as www.example.com/login.asp it actually calls login.php
3. Rewriting products.php?id=100 to products/psp/100 to make SEO friendly
Put this code in the htaccess file
RewriteEngine on
RewriteRule ^products/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ products.php?id=$2
Thats it for today. You can experiment a lot on .htaccess but be carefull it can open doors for security problems.
Here i will give you some .htaccess autogenertors
http://www.htaccesseditor.com/en.shtml
http://www.iwebtool.com/htaccess_url_rewrite
Nice one dude !