Vote

The URL Rewriting is a method of URLs rewriting that became essential for URLs simplification, particularly during the referencing of dynamic pages.

Installation

The main purpose of the URL Rewriting is to avoid having a coupling between the URL format and technical resources present on the server, as well as secondary gains the ability to improve the indexation of web browsers and to present less technical URLs.
The mod_rewrite module of Apache is usually present during the Apache installation :

The module can be activated thanks to the commande a2enmod :

Now we are going to indice to the Apache server to use the module by changing RewriteEngine :

Add this piece of configuration at the end of the file and safeguard :

Restart Apache for the update to take into account our configuration’s shift :


Configuration

In order to test the module’s proper functioning, we create a file PHP :

We do it again with the file .htaccess :

Your page http://www.domain.com/rewrite.php is now available via URL http://www.domain.com/rewrite.html

Activation of the URL rewriting.

Definition of the rewriting rule.

Regex of rewriting.

Searched string.

Parameter Last to indicate that it is the last rule to deal with.


Definition of rules

This time, we are going to see how to rewrite dynamic URLs composed of several parameters.
Let’s try to rewrite the following URLs :

http://www.domain.com/catalogue.php?page=cart&action=validate -> http://www.domain.com/cart.validate.html
http://www.domain.com/image.php?album=26&id=15 -> http://www.domain.com/image/26/15


Conditional rules

The conditional rewriting of URLs allows to filter and protect the access to a part of your web site or to ban someone trying to access it.
A conditional rule is declined under the following format :

Other examples :

Rules can be dynamic by using the following contextual variables :

Server’s domain.

the page (if there are information) where the visitor comes from.

Web browser and operating system, …

Required page in resquest HTTP/HTTPS.

IP address making the request.


Categories: SystemTutorials

JN Community

Les Ressources, en particulier les tutoriaux, présupposent que l’Utilisateur qui décide de les mettre en œuvre dispose des connaissances, des compétences et de l’expérience nécessaire pour cette mise en œuvre. L’Utilisateur disposant d’une connaissance, compétence et/ou expérience limitée ou insuffisante doit absolument s’abstenir de mettre en œuvre les Ressources par lui-même. Jaguar Network décline toute responsabilité quant aux conséquences dommageables de la mise en œuvre des Ressources, notamment sur les infrastructures informatiques de l’Utilisateur, de ses commettants ou préposés ou de tout tiers. Il est précisé en tant que de besoin que toute intervention de Jaguar Network visant à réparer les dommages causés par la mise en œuvre des Ressources par un Utilisateur ne disposant pas des connaissances, compétences et/ou expériences suffisantes sera facturée et fera l’objet d’un devis préalable et d’un bon de commande aux conditions des contrats Jaguar Network en vigueur.

Related Posts

System

Installation of a web server LEMP (Linux, Nginx, MySQL, PHP)

Vote The installation of a server LEMP Linux + Nginx + MySQL + PHP might be more useful and efficient than an Apache (server LAMP). Articles similaires

System

Operating load-balancing with HAproxy

Vote HAproxy is a software allowing Load-Balancing between several web servers by allocating requests in an almost transparent way for the user. Articles similaires

System

10 tips to write efficient scripts on Linux

Vote The shell script is the most simple type of programming you would write on Linux. Moreover, it is a necessary skill to automate your system administration tasks, to develop new simple features, … In Read more…