Make SEO URLs Friendly From your .httaccess


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.If you are running a WordPress blog then you most likely will not need to edit your .httaccess File to make it URLs SEO Friendly as WordPress already has plenty of SEO Friendly features and plugins.

1. Creating .htaccess file

If you don’t have a .httaccess file already created then create one and add the following lines if you already haven’t.

Options +FollowSymLinks   RewriteEngine On

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

2. Create your own rewrite rule

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…tname&price=30 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 </files>

Alternatively, if you are not able to do these things on your own there are a few online Online URL Rewritters, which will make everything easier and simpler for you:

URL Rewriting – Create Search Engine Friendly URLs…-generator.php
Mod Rewrite Generator by…enerator.shtml

Static URLs are known to be better than Dynamic URLs because of a number of reasons
1. Static URLs typically Rank better in Search Engines.
2. Search Engines are known to index the content of dynamic pages a lot slower compared to static pages.
3. Static URLs are always more friendlier looking to the End Users.

Example of a dynamic URL


This tool helps you convert dynamic URLs into static looking html URLs.

Example of the above dynamic URL Re-written using this tool


You would need to create a file called “.htaccess” and paste the code generated into it, Once you have created the .htacess file simply copy it into your web directory.
URL rewriting of this type would work ONLY if you are hosted on a Linux Server.

This tutorial was not fully written by me.

Leave A Reply

Please enter your comment!
Please enter your name here