D   A   T   A   W   O   K

Creation: January 01 1970
Modified: September 11 2018


Rewrite Rules

Most dynamic sites include variables in their URLs that tell the site what information to show the user. Typically, this gives URLs like the following:


The problem with this kind of URL structure is that is not memorable and not search engine "friendly".

A much more better URL is


URL rewrite is the transpation of the last url into something that the server chan understand. That is the original one.

The Apache module mod_rewrite allows you rewrite URL requests that come into your server and is based on a regular-expression parser.

The file .htaccess, located in the website root will contain the set of our rules. If the file contains some errors usually the server will display an error code "500".

Within the .htaccess file, any character following the # character is considered a comment.

The first step is the activation of the Apache rewrite engine. In the .htaccess file add the following at the beginning of the file

RewriteEngine   On

Basic example

Let's consider a simple example. We want to redirect every access to the following url:




For this to work we need a rewrite rule in the .htaccess file like the following:

RewriteRule     ^articles/?$    articles.php    [NC,L]