Making Friendly URLs

Posted on August 29, 2008, under PHP,  Bookmark it

The aim of this tutorial is to show you how to make SEO Friendly URLs. First of all you must check if your Apache Server has the mod_rewrite module enabled.

Too many parameters in an URL can create problems in crawling for a Search Engine. A friendly optimised URL would always be a better alternative if this option is available to you. These URLs are better indexed by Search Engines and people are more likely to click on static links which contain a description of what the link is about.

The rewriting rules should be written in the .htaccess file that must be created and uploaded in the main root of your site.

Here’s an example of a dynamic URL:

http://www.yourdomain.com/?c=5&p=20

A better (SEO) alternative of this URL would be:

http://www.yourdomain.com/articles/5/20-seo-techniques.html

You can obviously notice what this URL is about.

The server sends a request to the .htaccess file passing the category id and the post id.

The .htaccess file will look like this:

# Enable mod_rewrite
RewriteEngine On 

# Sets the base URL for per-directory rewrites
RewriteBase /

RewriteRule ^articles/([0-9]+)/([0-9]+)-seo-techniques.html$ /?c=$1&p=$2

We use regular expressions to tell the script that only numbers values should be parsed. The static url is automatically converted to the dynamic one.

Here are more examples of rewrite rules:

RewriteRule ^terms-and-conditions.html$ /index.php?module=terms

# example: http://www.mydomain.com/category/10/post/35/php-functions.html
RewriteRule ^category/([0-9]+)/post/([0-9]+)/(.*).html$ /?c_id=$1&p_id=$2

By using this rewrite techniques your URLs are better indexed by search engines and are more likely to have a higher rank.

Do you wish to receive the latest updates as soon as they are posted? Get our RSS Feed or Subscribe to the Newsletter!

Get our RSS Feed!

2 Replies to "Making Friendly URLs"

  1. Hi,

    Nice article, I did a similar but more detailed article in my blog: http://www.web-design-talk.co.uk/116/seo-friendly-urls-with-mod-rewrite/

    With regards to higher rankings for SEO URLs well that’s highly debatable, as Google recently said they make very little difference in the serps. The main advantage is a cleaner looking site and better usability for your users.

Leave a Reply


* = required fields

  (will not be published)


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Note: If you want to post CODE Snippets, please make them postable first!
(e.g. <br /> should be converted to &lt;br /&gt;)