Redirection PHP :
- <?php
- header('Location: '.get_bloginfo('url'));
- exit;
Redirection avec un .htaccess :
Redirect permanent : Ceci envoie un code HTTP 301 redirection permanente qui informe les navigateurs, et surtout les moteurs de recherche, qu'il faut mettre à jour leurs liens vers la nouvelle adresse.
Attention: Ne fonctionne pas pour faire pointer votre site dans un sous dossier. Pour cela utiliser DirectoryIndex?
Pour rediriger le site entier vers une nouvelle adresse :
- Redirect permanent / http://nouveau-site.tld/
Ex :
- # Redirections pour le référencement
- <IfModule mod_alias.c>
- Redirect 301 /39/un_media_totalement_durable.html http://jmlc.info
- Redirect 301 /101/le_livre_de_l’anniversaire_de_votre_entreprise.html http://jmlc.info
- </IfModule>
Pour changer un repertoire/fichier :
- Redirect permanent /ancien_repertoire http://nouveau-site.tld/nouveau_repertoire
- Redirect permanent /ancien_fichier.php http://site.tld/nouveau_fichier.php
Global http to https :
- # SSL/HTTPS
- <IfModule mod_alias.c>
- RewriteEngine On
- RewriteCond %{HTTPS} !on
- RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
- </IfModule>
It's better to use a virtualhost to do that but that's the best way to do it on shared hosting : Doc StackOverflow
Plus d'infos et de redirections : Source
Documentation apache
Redirection javascript
jQuery is not necessary, and window.location.replace(…) will best simulate an HTTP redirect.
It is better than using window.location.href =, because replace() does not put the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco. If you want to simulate someone clicking on a link, use location.href. If you want to simulate an HTTP redirect, use location.replace.
For example:
- // similar behavior as an HTTP redirect
- window.location.replace("http://stackoverflow.com");
- // similar behavior as clicking on a link
- window.location.href = "http://stackoverflow.com";