Using mod_rewrite to convert dynamic URLs to SEO friendly URLs

SEO friendly URLs  (sometimes also known as Semantic URL or clean URL )  are intended to improve the readability and accessibility of the website. Nowadays these URLs play an important role improving the page rank. Below is the difference between a semantic and non-semantic URLs.

Non-Semantic URL Semantic URL

It is very easy to create semantic URLs using mod_rewrite. So let’s jump into it

STEP 1: Create a file named index.php

Create the file write the following code.


STEP 2: Create a file named user.php

Create the file for redirection purpose.


STEP 3. Create a file named .htaccess

Create the file named .htaccess. You may run into problems while creating this file as it doesn’t have any name.  So all you have to is to save the file by name


(including the quotes).

Now use mod_rewrite in your .htaccess file to parse out the elements of the URL. Like this:


The line starting with the # symbol are the comments. Line after the first comment is used to remove the .php extension from the file name. In last  line the ([^\.]+) pulls the elements out and puts them in variables $1.

Now run the file in your favorite browser.


Click on any link and see the magic. You can see that URLs are now semantic and easy to read.

screenshot-42 Hope this is useful. If you have any doubts then please do comment in the section below. I will try my best to answer the questions.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s