Rewrite/Redirect rules Apache
From Tuxunix
Contents |
redirection vers page de maintenance
#Maintenance
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteRule $ /maintenance.html [R=302,L]
redirection vers page de maintenance sauf pour certaines IP
#page dattente
RewriteCond %{Remote_Addr}% !X.X.X.X
RewriteCond %{Remote_Addr}% !X.X.X.X
RewriteCond %{Request_Uri}% !/attente/*
RewriteRule ^/(.*)$ /attente/index.html [R=302,L]
# Fin bloc page d'attente
Condition de redirection selon des IP différentes
RewriteCond %{SERVER_ADDR} 192\.168\.0\.23
RewriteRule ^/images/visu.action$ https://www.tuxunix.com/images/visu.action
RewriteCond %{SERVER_ADDR} 192\.168\.0\.37
RewriteRule ^/images/visu.action$ https://192.168.0.37/images/visu.action
Redirection permanent (301)
Signifie une redirection définitive, permet au moteur de recherche de remplacer l'URL par l’adresse destinataire de la redirection.
Redirect permanent PAGE
Redirect permanent /toto/client.php http://www.monnouveaudomaine.fr/client
Redirect permanent SITE
RedirectPermanent / http://www.monnouveaudomaine.fr/
Redirect permanent DOSSIER
RedirectPermanent /ancienDossier http://www.monnouveaudomaine.fr/nouveauDossier
Redirect permanent avec condition (Appliqué sur un nom de domaine précis)
RewriteCond %{HTTP_HOST} ^www.mondomaine.fr$ [OR]
RewriteCond %{HTTP_HOST} ^mondomaine.fr$
RewriteRule /fichier.php http://mondomaine/fichier.php [R=301,L]
Redirection temporaire(302)
Signifie une redirection temporaire
Redirect PAGE
Redirect /anciendossier/ancienneadresse.html http://www.domaine.fr/dossierprovisoire/fichierprovisoire.html
Redirect SITE
Redirect / http://www.domaine-temporaire.fr/
Redirect DOSSIER
Redirect /anciendossier http://www.domaine-temporaire.fr/dossierprovisoire
Intégrer dans une page PHP
<?php header(”Location: http://www.domaine-temporaire.fr/dossierprovisoire/fichierprovisoire.html”); exit(); ?>
Liste FLAG
[R] Redirect you can add an =301 or =302 to change the type.
[F] Forces the url to be forbidden. 403 header
[G] Forces the url to be gone 401 header
[L] Last rule. (You should use this on all your rules that don't link together)
[N] Next round. Rerun the rules again from the start
[C] Chains a rewrite rule together with the next rule.
[T] use T=MIME-type to force the file to be a mime type
[NS] Use if no sub request is requested
[NC] Makes the rule case INsensitive
[QSA] Query String Append use to add to an existing query string
[NE] Turns of normal escapes that are default in the rewriterule
[PT] Pass through to the handler (together with mod alias)
[S] Skip the next rule S=3 skips the next 3 rules
[E] E=var sets an enviromental variable that can be called by other rules
Gestion des domaines avec Accent (IDN)
- Punycode (littéralement « code chétif ») est une syntaxe de codage définie dans la RFC 3492 et conçue pour être utilisée en adéquation avec les noms de domaines internationalisés dans les applications les supportant
Exemple pour énergissime.com :
ServerAlias xn--nergissime-96a.com ServerAlias www.xn--nergissime-96a.com
Convertisseur punycode : [1]

