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:
<?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:
echo 'Welcome to the homepage';
To create the file articles.php, execute the following command:
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:
echo 'Error, this page does not exist !';
You like this tutorial ?
Like this website in order to promote it on facebook !