Posted on Thursday 18 January 2007

mod_rewrite - definition

“mod_rewrite” is an extension module for the world’s most popular webserver, called Apache.

mod_rewrite - what does it do

“mod_rewrite” is used to rewrite webpage urls, especially dynamic urls including folder paths, variables and file extensions.

seo with mod_rewrite

The main reason for the rewriting of webpages for seo purposes lies in the fact that most search engines give static webpages a better ranking in the SERPS (Search Engine Result Pages). If a dynamic url is internally rewritten by mod_rewrite, it still is dynamic technically, but appears static to the Search Engine Robots that are crawling the site. This is especially important when it comes to Google Pagerank (TM Google Inc.).

mod_rewrite url examples

before = index.php?page=1&user=2&sessionID=123456789

after = /1/2/123456789/ - (static look)

before = index.php?category=seo&date=1-17-2007&postID=54321

after = /seo/1-17-2007/mod_rewrite-basics.html - (static look, added thread title)

mod_rewrite seo-strategy

For SEO purposes it is recommended to insert topic-relevant keywords into the url, such as the title of the page or the category. This is not neccessarily needed though, the most important part is the static appearance.

Implementation of mod_rewrite

For implementation of mod_rewrite functionality into your website you need to have Apache installed with the mod_rewrite extension module.

There are two ways of setting the rewrite directives:

#1 In a .htaccess file

- should be in the root folder of the webspace application, the path of which you want to modify

Here’s an example .htaccess file’s content (the one which is used for this website)


RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

#2 In your server’s Apache httpd.conf

The syntax used in the httpd.conf code slightly differs from .htaccess code.

You can read on about the technical implementation, there’s a full documentation on mod_rewrite at the Apache Website.


3 Comments for 'mod_rewrite basics'

  1.  
    February 17, 2007 | 2:20 pm
     

    […] A 301 redirect command is typically inserted into a .htaccess file on the website’s root directory, similar to mod_rewrite url rewrite directives. It’s a simple file in regular text format named .htaccess, pay attention to the dot at the beginning. Usually files are named like “name.extension”, this file is different though - from a technical point of view the file could be considered unnamed and having the extension “htaccess”. […]

  2.  
    Terabanitoss
    May 9, 2007 | 2:17 pm
     

    Hello
    You are The Best!!!
    G’night

  3.  
    May 29, 2007 | 12:42 pm
     

    […] is by default a quite search engine friendly blog software. One of the nice built-in features is a mod-rewrite function that enables you to change the layout of your wordpress blog’s permalink structure. […]

Leave a comment

(required)

(required)


Information for comment users
Line and paragraph breaks are implemented automatically. Your e-mail address is never displayed. Please consider what you're posting.

Use the buttons below to customise your comment.


RSS feed for comments on this post | TrackBack URI