Outils pour utilisateurs

Outils du site


applications:web:apache:rewrite

Apache Web Server


Mod Rewrite : Redirection et réécriture d'URL


Il faut activer le module rewrite dans /etc/sysconfig/apache2

Redirection vers un sous repertoire

<VirtualHost *:80>
...
 RewriteEngine On
 RewriteRule ^/$ /in/ [L,R=301]
...
</VirtualHost>

Récriture d'URL

Exemple : bionateo.fr

.htaccess

SetEnv REGISTER_GLOBALS 0
SetEnv ZEND_OPTIMIZER 1
SetEnv MAGIC_QUOTES 1
SetEnv PHP_VER 5
 
#--------------------------------------------------
# Répertoire : /articles/
#--------------------------------------------------

# Le serveur doit suivre les liens symboliques :
Options +FollowSymlinks
 
# Activation du module de réécriture d'URL :
RewriteEngine on
 
#--------------------------------------------------
# Règles de réécriture d'URL :
#--------------------------------------------------

RewriteRule ^liste_articles.html$   			index.php?p=divers&c=listearticles [L]
 
 
# Article sans numéro de page :	(art-RAYON_ID-ARTICLE_ID-NOM_ARTICLE.html)
RewriteRule ^art-([0-9]+)-([0-9]+)-(.*)\.html$   	/bionateo/article.php?r=$1&a=$2 [L]
 
# Rayon	
RewriteRule ^rayon-([0-9]+)-(.*)\.html$   		/bionateo/rayon.php?r=$1 [L]
RewriteRule ^rayon-R([0-9]+)-M([0-9]+)-(.*)\.html$      /bionateo/rayon.php?r=$1&m=$2 [L]
 
# Marque
RewriteRule ^marque-([0-9]+)-(.*)\.html$   	        /bionateo/rayon.php?c=marque&m=$1 [L]
 
# Lien pagination
RewriteRule ^rayon-R([0-9]+)-P([0-9]+)-(.*)\.html$   	/bionateo/rayon.php?r=$1&cp=$2 [L]
RewriteRule ^rayon-R([0-9]+)-C([a-zA-Z]*)-M([0-9]+)-P([0-9]+)-(.*)\.html$   	/bionateo/rayon.php?r=$1&c=$2&m=$3&cp=$4 [L]
 
RewriteRule ^rayon-R([0-9]+)-C(\D*)-M([0-9]+)-(.*)\.html$   /bionateo/rayon.php?r=$1&c=$2&m=$3 [L]

applications/web/apache/rewrite.txt · Dernière modification : 2022/06/22 18:07 de zandor