This tutorial explains how to configure your apache2 server by using an .htaccess in order to rewrite URLs.
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).
The URL rewriting consists to put in place a system in order to have a specific URL for each generated page on the web server. For example, when a user want to access to the page http://www.tutorielsenfolie.com/articles-7.html, the server must return exactly the same thing as if he had requested access to the page: http://www.tutorielsenfolie.com/?page=articles&id=7 (If the user doesn't rewrite the URL).
The correspondence between these two URL schemes is using regular expression to retrieve the values of different variables.
Apache2 server configuration
First of all, we will configure the web server in order to use the URL rewriting. To do that, we will activate the rewriting module with the following command:
(To deactivate the rewriting, you need to execute the following command: a2dismod rewrite).
Now, that the rewriting module is deactivated, we will allow the root folder to use the URL rewriting mechanism. To do that, execute the following command:
Add now, the lines below at the end of the file.
The above lines allow rewriting the URL in the root folder of your website.
Testing and implementation of road
Now, we will test if the rewriting works fine. To do that, create a file .htaccess. To do that, execute the following command:
RewriteRule ^(.*)$ routur.php [L]
Then create the file router.php. To do that, execute the following command:
nano /var/www/tutorielsenfolie/ routur.php
Now we will test the URL rewriting. Go to « http://localhost/tutorielsenfolie/test.html » on your browser. If the redirection works fine, you will see the message OK. If it is not the case, the server is not (or not well) configured.
You like this tutorial ?
Like this website in order to promote it on facebook !