Galactic Civilizations 3
Defining routes for the URL rewriting

Defining routes for the URL rewriting

Category: Php.
Posted by on the 19/12/2013.
Last update on the 22/12/2013.

<<Previous tutorial    Next tutorial>>


This tutorial explains how to define an URL schema in order to redirect the user to a dynamic page during the url rewriting.


This tutorial is intended for people under Linux that use apache2 server as webserver. In this tutorial we consider that the root folder of your website is /var/www/tutorielsenfolie. Furthermore, all commands in this tutorial are executed as root. (su command).

Defining the url schema

First of all we need to define the url schema with the help of an XML file and a regular expression. To do that, execute the following command:

nano /var/www/tutorielsenfolie/routes.xml


<?xml version="1.0" encoding="iso-8859-1" ?>
    <route url="/tutorielsenfolie/" file="homepage.php" />
    <route url="/tutorielsenfolie/articles-([0-9]+).html" file="articles.php" vars="id" />

The XML file allows knowing to which file the request should be redirected. This redirection depends on the URL asked by the user.

Dynamic creation of pages

Now we will create the pages: homepage.php and articles.php. To create the file homepage.php, execute the following command:

nano /var/www/tutorielsenfolie/homepage.php


echo 'Welcome to the homepage';

To create the file articles.php, execute the following command:

nano /var/www/tutorielsenfolie/articles.php


echo 'Here is the article number : '.$_GET['id'];

We will also create an error page if the user wants to access a file for which he has no permission. To do that, execute the following command:

nano /var/www/tutorielsenfolie/404.php


echo 'Error, this page does not exist !';

You like this tutorial ?
Like this website in order to promote it on facebook !

<<Previous tutorial    Next tutorial>>

You like this tutorial ? Share it with your friends !
Partager sur Facebook Partager sur Twitter Partager sur Myspace Partager sur Stumbleupon Soumettre sur Reddit Partager sur Digg Ajouter à vos favoris Technorati Ajouter à vos favoris Live Ajouter à vos favoris Google Ajouter sur vos favoris Yahoo