Creating SEO friendly URL using htaccess

Creating SEO friendly URL requires a knowledge on how htaccess works. Not just that, you should also be familiar with Regular Expressions but I won’t cover that one in this post though since we’ll be focusing on putting those in htaccess. Now, let’s get our hands dirty.

For example:
http://mysite.com/profile.php?username=JuanDelaCruz

If you wanted that one to become
http://mysite.com/user/JuanDelaCruz/

This is what you’re going to do:

#RewriteEngine On
#RewriteCond %{REQUEST_FILENAME} !-d 
#RewriteCond %{REQUEST_FILENAME}\.php -f 
#RewriteRule ^(.*)$ $1.php

# Use the following rule if you want to make the page like a directory
RewriteCond %{REQUEST_URI} !^/user/profile.php
RewriteRule ^user/(.*[^/])$ user/$1/ [R=301,L]

# The following rewrite the other way round:
RewriteCond %{REQUEST_URI} ^/profile.php
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /profile.php
RewriteCond %{QUERY_STRING} id=([^&]+)
RewriteRule ^profile.php$ user/%1?

There are comments, so hope you can understand it from there.
Hope this helps someone! Have a Happy Coding! :)