Create SEO Friendly URLs With Htaccess Mod Rewrite in 3 Easy Steps

Posted in SEO , Web Development on 18 November 2009 55 comments

What is SEO Friendly URL and Why?

An example of SEO friendly URL can be seen in this page. Compare it with urls like , you will find it easier to remember and the it also clearly tells you what this page is about. Furthermore, the words in the URL might match the search keywords, bringing more traffic from search engines.

Make SEO friendly URL yourself

I don’t have to worry about SEO friendly URL in WordPress since its already built-in. However, I need it for my premium wordpress themes website, which is not based on WordPress. So I started to look into this matter.

Using htaccess and mod rewrite, you can make SEO friendly yourself in 3 easy steps.

1. Creating .htaccess file

Open NotePad (yes, the windows notepad) > File > Save As > Change the “Save as Type” to “All Files” > enter “.htaccess” as the name and press Save. You’ve created a htacces file.

Now paste this codes below into it.

Options +FollowSymLinks
RewriteEngine On

The first line Options +FollowSymLinks is required for some server configurations.

2. Create your own rewrite rule

Example 1
For example, if you want to change links like to, here’s the rewrite rule.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^topic/([a-zA-Z0-9]+)/$ index.php?topic=$1

• Like regular expressions, the [a-zA-Z0-9] matches lower and uppercase of alphabets and numbers.
• The asterisk inside the brackets + is a quantifier that match 1 occurence to infinite occurences.
• Combining them, ([a-zA-Z0-9]+) matches alphanumerics of at least 1 character.
• The caret ^ means “start with”, meaning the URL starts with the word “topic”.
• The dollar sign $ means “end”, meaning the URL ends with a slash.
• The $1 is backreference, it carries the content of the first group of brackets.

In other words, when user enters , the page being called and run would be

Example 2
If you want to change URLs like to Basically its similar to above.

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^products/([a-zA-Z]+)/([0-9]+)/$ index.php?product=$1&price=$2

• The [0-9] in matches numbers only.
• The plus sign is a quantifier that match 1 or more occurences.
• Combining them, ([0-9]+) means 1 or more numbers.
• Similarly, $1 will be the first brackets : product name and $2 would be the second brackets : price.

Example 3
If you want to change URLs like to, here’s how:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^article-([0-9]+)\.html$ article.php?id=$1

• The new thing here is the \. (backslash followed by a dot).
• The backslash here “escapes” the dot, so that the dot means a real dot instead of “anything”.

3. Extra Stuff

Custom 404 error page

Put this in your htaccess if you would like to have a custom 404 error page instead of the default one.

ErrorDocument 404 /404.php

Change the 404.php to your page.

Disable directory browsing

For security purpose, its best to disable directory browsing so that people won’t know what files you have. Use this :

Options All -Indexes
Protect .htaccess files

This should disallow other to access your .htaccess file, just like disallowing others to access your wordpress’s wp-config.php

<files .htaccess>
order allow,deny
deny from all

Others references you might need

Mod Rewrite Syntax


Posted by Zen on 18 November 2009 • 214,873 visits 55 comments
Tags : ,

or Subscribe to specific category only :


Toronto Internet Marketing says:

i can imagine it hurts for some people when they find out a long time after they made their URL that their URL is not keyword friendly. After you have built many bcklinks, gotten your reputation, and you have a long lasting domain age.

Doreen says:

Hi Thank u for the Tipps. What is the right Backend-Setting in Permalinks of WordPress.

Allgemeine Optionen: only in german here?
Tag und Name
Monat und Name
Benutzerdefinierte Struktur

zen says:

For wordpress, I use “Custom Structure” : /%postname%/

Cheers :)

Gary says:

Very helpful post. It has been very difficult for me to find anything good on this topic. thanks.

mark says:

thanks, that was a nice post to go through, I look forward to reading more of your stuff

sovanndy says:

Could you explain about (.*?)?

what does it mean?

I don’t understand this rule

car freak says:

great tips,,thanks a lot

Tanya says:

Ey, what about phpbb3? it is possible do something like that in forums? i found all the time mods like Phpbb seo, but it means a lot of changings the i don’t wanna do.

thanks for the tips!!!

Aurora says:

I too have that problem. This I tried and it only shows on the tab not on the web address in phpbb 3.07_pl. I tried the “easy mod” and that just gave me a blank page and it was NOT easy, so I had to reinstall my board. I hope they find a good solution soon. :)

Balaji J H says:

Thanks a lot
You saved me others worked but redirects to the real url
Only yours does the work


Nayan Paul says:

Thanks Sir , Very Handy and useful post..

I have some query about seo friendly url,please help me

My demo site URL looks like
And Now loooks URL in that format

How i do that thru htaccess ? please Help Me , Thanks Again….

Ranjan says:

Hey, anybody can help me. I couldn’t able to do url rewriting.
here is my code of “.htaccess” file,

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^name/(.*)/$ rewrite.php?name=$1

Jyoti says:

Hi, Ranjan, Sory i couldn’t get u…
anybody can help him? thanks in advance.

Dhruv Kumar S says:

Hi Ranjan,

If your url is

and if you want it to be like

Use this

Options +FollowSymLinks
RewriteEngine On

RewriteRule ^name/(.*)/$ rewrite.php?name=$1

And make sure your rewrite.php file is written accordingly.

Abhi says:

Hey what to change in rewrite.php file ? thanks in advance

news and updates says:

thanks for your great and value share, actually i’ve been searching for a couple days for it

news and updates says:

i’ve find your blog appear on google, think you have good Seo technic, great job anyway.

Real Estate Analysis says:

Thanks for the easy to follow guide. I needed to create the SEO url’s on my website for a long time, but always had troubles to figure it out. Now I just copied your code, change it a bit and it works like a charm! Thanks.

Needa says:

awesome its helpful :D

Helloo says:


its help my URL be search engine friendly :)

Karnataka Medical says:

u gave the information in simple words. ^ key should always be used if it is the start of string which is to be matched, otherwise it will be matching URL names from in-between also, which may create trouble.

medical assistant says:

I tried the follwoing with no sucess:

RewriteRule ^directory/(.*)/$ index.php?q=$1 [L]


output to my script:

Can somebody tell me what am i doing wrong?

zen says:

You missed a slash after “123″

Milos says:

Hello, it’s a very good post. I have a little problem:
My pages is:

I want rewrite this pages as:

I made a .htaccess file like this:
Options +FollowSymLinks

RewriteEngine On
RewriteRule ^article-([0-9]+)\.html$ index.php?=detalji?$1

But when i tipe a I give onli index.php page, not index.php?=detalji?221

Do you now where I make a mistake?

Tnx a lot,
Milos Popovic

learning and teaching says:

great post with good information. Is it possible to make to browse like a subdomain with .htaccess ?if yes how do i code it ?bro

chand says:


i have tried whatever show in this post. but my url is notwoking. see the url and suggesst me how to modify
if i am clicking on any of the menu it is coming like
but in need something like

my code is like
RewriteRule ^/100bestbuy/products/(.*)/$ 100bestbuy/search.php?categoryId=$1 [L,NC]

i am trying from 3 day but no result in localhost aswellas in server.
help me please…………….

Zen says:

perhaps you can try this:

RewriteRule ^100bestbuy/products/(.*)/$ 100bestbuy/search.php?categoryId=$1

and put the htaccess file in root.

gozada says:

Hey, anybody can help me. I couldn’t able to do url rewriting.
here is my code of “.htaccess” file,

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^name/(.*)/$ rewrite.php?name=$1

thank you

a.r.bhuyan says:

its very important issue for seo learner .thanks for this post.

Bill Wynne says:

Great tips using the htaccess file!

Zeeshan Parvez says:

Just what the doctor ordered! Exactly what I was looking for to integrate with my cms. I needed a way to get seo friendly urls. Now I have the answer. Thanks!

Jaybee says:

I have scanned the internet for a mod rewrite solution to turn my urls from:
to (like they do in WordPress)
And I do not want to pass numbers in the urls.

It has forced me to hard code all my dynamic links in my htaccess which becomes tiresome when you add more content onto the website because this method is not automated. eg.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^the-team$ index.php?section=this&catid=1&articleid=15 [NC,L]

Please help me come up with a workable automating solution just like they do in WordPress. Note: All the content is stored in a database.

google places says:

Very useful list Zen, .htacces is something I’ve always struggled with and this has helped me get my head around it a bit. Before it was trial and error really but this has helped me understand why I’m actually using each separate line of code. Cheers

mitra says:

Hi Zen, really its a very good tutorial…..
But I have a problem with url rewriting.
My present link is
and I want http://localhost/htaccess/products/computer/5/
So how can I do it? and what should I write within href=”"?
basic folder structure is —
And presently the hyperlink file is within index.php at root folder.

And another thing, there are similar pages like product.php and corresponding different parameters, suppose—
and I need as same as above
So is it possible to write just one rewriteRule to do these all?
if yes, then how?

Thank you.

Arvind says:


I have been trying on localhost to rewrite this URL (http://localhost/cms/categories.php?id=1) to (http://localhost/cms/category/1)

I used the following rewrite condition (and also others) in .htaccess file but everytime it has been failed:

Options +FollowSymlinks
RewriteEngine On
RewriteRule ^cms/category/([0-9]+)$ /cms/categories.php?id=$1 [R,L]

can anybody help me to tell where I am wrong?

Thanks for help in advance

arif says:

i have a url like this

http://abc.local/stock/detail.php?id=1 i need to change this like


i need to show product title which will come from the database

kindly give me a example of my problem


Toko Online says:

Nice, with htaccess rewrite rule every web url looks easy.


  1. Step 2: SEO Friendly URL | Siddharth Shah | Sid | Siddhath SEO Tips | Sid photography
  2. .htaccess REWRITE RULES | .htaccess REWRITE RULES - .htaccess REWRITE RULES - .htaccess REWRITE RULES = .htaccess REWRITE RULES | NURSING CARE
  3. how can i remove .html from url? - Bizzteams - Page 2

Leave a Reply

You must be logged in to post a comment.

Previous Post
Next Post