Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| webdev:redirections [16/01/2016 21:20] – modification externe 127.0.0.1 | webdev:redirections [25/04/2019 19:57] (Version actuelle) – dolo | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ====== Redirections de pages ====== | ||
| + | [[https:// | ||
| + | **Redirection PHP :** | ||
| + | <Code linenums><? | ||
| + | header(' | ||
| + | exit;</ | ||
| + | |||
| + | **Redirection avec un .htaccess :** | ||
| + | |||
| + | Redirect permanent : Ceci envoie un code HTTP 301 redirection permanente qui informe les navigateurs, | ||
| + | |||
| + | 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 : | ||
| + | |||
| + | <Code linenums> | ||
| + | |||
| + | Ex : | ||
| + | <Code linenums> | ||
| + | # Redirections pour le référencement | ||
| + | < | ||
| + | Redirect 301 / | ||
| + | Redirect 301 / | ||
| + | </ | ||
| + | </ | ||
| + | |||
| + | Pour changer un repertoire/ | ||
| + | <Code linenums> | ||
| + | Redirect permanent / | ||
| + | |||
| + | Global http to https : | ||
| + | <Code linenums> | ||
| + | # SSL/HTTPS | ||
| + | < | ||
| + | RewriteEngine On | ||
| + | RewriteCond %{HTTPS} !on | ||
| + | RewriteRule (.*) https:// | ||
| + | </ | ||
| + | </ | ||
| + | It's better to use a virtualhost to do that but that's the best way to do it on shared hosting : [[https:// | ||
| + | |||
| + | |||
| + | Plus d' | ||
| + | [[http:// | ||
| + | |||
| + | **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(" | ||
| + | |||
| + | // similar behavior as clicking on a link | ||
| + | window.location.href = " | ||
| + | </ | ||
| + | |||
| + | |||
| + | [[http:// | ||