D   A   T   A   W   O   K





Creation: January 01 1970
Modified: September 11 2018

HTACCESS File

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:

http://www.davelog.net/article.php?file_id=3

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

A much more better URL is

http://www.davelog.net/article/3

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:

http://davelog.net/articles

To

http://davelog.net/articles.php

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

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

References

davxy