diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 06:33:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 06:33:50 +0000 |
commit | fe39ffb8b90ae4e002ed73fe98617cd590abb467 (patch) | |
tree | b80e5956907d8aeaaffe4e4f0c068c0e6157ce8b /docs/manual/rewrite/avoid.html | |
parent | Initial commit. (diff) | |
download | apache2-upstream.tar.xz apache2-upstream.zip |
Adding upstream version 2.4.56.upstream/2.4.56upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | docs/manual/rewrite/avoid.html | 9 | ||||
-rw-r--r-- | docs/manual/rewrite/avoid.html.en | 254 | ||||
-rw-r--r-- | docs/manual/rewrite/avoid.html.fr.utf8 | 271 |
3 files changed, 534 insertions, 0 deletions
diff --git a/docs/manual/rewrite/avoid.html b/docs/manual/rewrite/avoid.html new file mode 100644 index 0000000..92bbe36 --- /dev/null +++ b/docs/manual/rewrite/avoid.html @@ -0,0 +1,9 @@ +# GENERATED FROM XML -- DO NOT EDIT + +URI: avoid.html.en +Content-Language: en +Content-type: text/html; charset=UTF-8 + +URI: avoid.html.fr.utf8 +Content-Language: fr +Content-type: text/html; charset=UTF-8 diff --git a/docs/manual/rewrite/avoid.html.en b/docs/manual/rewrite/avoid.html.en new file mode 100644 index 0000000..b572a2a --- /dev/null +++ b/docs/manual/rewrite/avoid.html.en @@ -0,0 +1,254 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head> +<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> +<!-- + XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + This file is generated from xml source: DO NOT EDIT + XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + --> +<title>When not to use mod_rewrite - Apache HTTP Server Version 2.4</title> +<link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> +<link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> +<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" /> +<script src="../style/scripts/prettify.min.js" type="text/javascript"> +</script> + +<link href="../images/favicon.ico" rel="shortcut icon" /></head> +<body id="manual-page"><div id="page-header"> +<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p> +<p class="apache">Apache HTTP Server Version 2.4</p> +<img alt="" src="../images/feather.png" /></div> +<div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div> +<div id="path"> +<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.4</a> > <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>When not to use mod_rewrite</h1> +<div class="toplang"> +<p><span>Available Languages: </span><a href="../en/rewrite/avoid.html" title="English"> en </a> | +<a href="../fr/rewrite/avoid.html" hreflang="fr" rel="alternate" title="Français"> fr </a></p> +</div> + + +<p>This document supplements the <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> +<a href="../mod/mod_rewrite.html">reference documentation</a>. It describes +perhaps one of the most important concepts about <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> - namely, +when to avoid using it.</p> + +<p><code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> should be considered a last resort, when other +alternatives are found wanting. Using it when there are simpler +alternatives leads to configurations which are confusing, fragile, and +hard to maintain. Understanding what other alternatives are available is +a very important step towards <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> mastery.</p> + +<p>Note that many of these examples won't work unchanged in your +particular server configuration, so it's important that you understand +them, rather than merely cutting and pasting the examples into your +configuration.</p> + +<p>The most common situation in which <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> is +the right tool is when the very best solution requires access to the +server configuration files, and you don't have that access. Some +configuration directives are only available in the server configuration +file. So if you are in a hosting situation where you only have .htaccess +files to work with, you may need to resort to +<code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>.</p> + +</div> +<div id="quickview"><a href="https://www.apache.org/foundation/contributing.html" class="badge"><img src="https://www.apache.org/images/SupportApache-small.png" alt="Support Apache!" /></a><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#redirect">Simple Redirection</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#alias">URL Aliasing</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#vhosts">Virtual Hosting</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#proxy">Simple Proxying</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#setenv">Environment Variable Testing</a></li> +</ul><h3>See also</h3><ul class="seealso"><li><a href="../mod/mod_rewrite.html">Module documentation</a></li><li><a href="intro.html">mod_rewrite introduction</a></li><li><a href="remapping.html">Redirection and remapping</a></li><li><a href="access.html">Controlling access</a></li><li><a href="vhosts.html">Virtual hosts</a></li><li><a href="proxy.html">Proxying</a></li><li><a href="rewritemap.html">Using RewriteMap</a></li><li><a href="advanced.html">Advanced techniques</a></li><li><a href="#comments_section">Comments</a></li></ul></div> +<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="redirect" id="redirect">Simple Redirection</a></h2> + + +<p><code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code> provides the <code class="directive"><a href="../mod/mod_alias.html#redirect">Redirect</a></code> and <code class="directive"><a href="../mod/mod_alias.html#redirectmatch">RedirectMatch</a></code> directives, which provide a +means to redirect one URL to another. This kind of simple redirection of +one URL, or a class of URLs, to somewhere else, should be accomplished +using these directives rather than <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code>. <code>RedirectMatch</code> +allows you to include a regular expression in your redirection criteria, +providing many of the benefits of using <code>RewriteRule</code>.</p> + +<p>A common use for <code>RewriteRule</code> is to redirect an entire +class of URLs. For example, all URLs in the <code>/one</code> directory +must be redirected to <code>http://one.example.com/</code>, or perhaps +all <code>http</code> requests must be redirected to +<code>https</code>.</p> + +<p>These situations are better handled by the <code>Redirect</code> +directive. Remember that <code>Redirect</code> preserves path +information. That is to say, a redirect for a URL <code>/one</code> will +also redirect all URLs under that, such as <code>/one/two.html</code> +and <code>/one/three/four.html</code>.</p> + +<p>To redirect URLs under <code>/one</code> to +<code>http://one.example.com</code>, do the following:</p> + +<pre class="prettyprint lang-config">Redirect "/one/" "http://one.example.com/"</pre> + + +<p>To redirect one hostname to another, for example +<code>example.com</code> to <code>www.example.com</code>, see the +<a href="remapping.html#canonicalhost">Canonical Hostnames</a> +recipe.</p> + +<p>To redirect <code>http</code> URLs to <code>https</code>, do the +following:</p> + +<pre class="prettyprint lang-config"><VirtualHost *:80> + ServerName www.example.com + Redirect "/" "https://www.example.com/" +</VirtualHost> + +<VirtualHost *:443> + ServerName www.example.com + # ... SSL configuration goes here +</VirtualHost></pre> + + +<p>The use of <code>RewriteRule</code> to perform this task may be +appropriate if there are other <code>RewriteRule</code> directives in +the same scope. This is because, when there are <code>Redirect</code> +and <code>RewriteRule</code> directives in the same scope, the +<code>RewriteRule</code> directives will run first, regardless of the +order of appearance in the configuration file.</p> + +<p>In the case of the <em>http-to-https</em> redirection, the use of +<code>RewriteRule</code> would be appropriate if you don't have access +to the main server configuration file, and are obliged to perform this +task in a <code>.htaccess</code> file instead.</p> + +</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="alias" id="alias">URL Aliasing</a></h2> +<p>The <code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code> directive +provides mapping from a URI to a directory - usually a directory outside +of your <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>. Although it +is possible to perform this mapping with <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>, +<code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code> is the preferred method, for +reasons of simplicity and performance.</p> + +<div class="example"><h3>Using Alias</h3><pre class="prettyprint lang-config">Alias "/cats" "/var/www/virtualhosts/felines/htdocs"</pre> +</div> + +<p> +The use of <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> to perform this mapping may be +appropriate when you do not have access to the server configuration +files. Alias may only be used in server or virtualhost context, and not +in a <code>.htaccess</code> file. +</p> + +<p>Symbolic links would be another way to accomplish the same thing, if +you have <code>Options FollowSymLinks</code> enabled on your +server.</p> +</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="vhosts" id="vhosts">Virtual Hosting</a></h2> +<p>Although it is possible to handle <a href="vhosts.html">virtual hosts +with mod_rewrite</a>, it is seldom the right way. Creating individual +<code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> blocks is +almost always the right way to go. In the +event that you have an enormous number of virtual hosts, consider using +<code class="module"><a href="../mod/mod_vhost_alias.html">mod_vhost_alias</a></code> to create these hosts automatically.</p> + +<p>Modules such as <code class="module"><a href="../mod/mod_macro.html">mod_macro</a></code> are +also useful for creating a large number of virtual hosts dynamically.</p> + +<p>Using <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> for vitualhost creation may be +appropriate if you are using a hosting service that does not provide +you access to the server configuration files, and you are therefore +restricted to configuration using <code>.htaccess</code> files.</p> + +<p>See the <a href="vhosts.html">virtual hosts with mod_rewrite</a> +document for more details on how you might accomplish this if it still +seems like the right approach.</p> + +</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="proxy" id="proxy">Simple Proxying</a></h2> + +<p><code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> provides the <a href="flags.html#flag_p">[P]</a> flag to pass rewritten URIs through +<code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code>.</p> + +<pre class="prettyprint lang-config">RewriteRule "^/?images(.*)" "http://imageserver.local/images$1" [P]</pre> + + +<p>However, in many cases, when there is no actual pattern matching +needed, as in the example shown above, the <code class="directive"><a href="../mod/mod_proxy.html#proxypass">ProxyPass</a></code> directive is a better choice. +The example here could be rendered as:</p> + +<pre class="prettyprint lang-config">ProxyPass "/images/" "http://imageserver.local/images/"</pre> + + +<p>Note that whether you use <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> or <code class="directive"><a href="../mod/mod_proxy.html#proxypass">ProxyPass</a></code>, you'll still need to use the +<code class="directive"><a href="../mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code> directive to +catch redirects issued from the back-end server:</p> + +<pre class="prettyprint lang-config">ProxyPassReverse "/images/" "http://imageserver.local/images/"</pre> + + +<p>You may need to use <code>RewriteRule</code> instead when there are +other <code>RewriteRule</code>s in effect in the same scope, as a +<code>RewriteRule</code> will usually take effect before a +<code>ProxyPass</code>, and so may preempt what you're trying to +accomplish.</p> + +</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="setenv" id="setenv">Environment Variable Testing</a></h2> + +<p><code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> is frequently used to take a particular +action based on the presence or absence of a particular environment +variable or request header. This can be done more efficiently using the +<code class="directive"><a href="../mod/core.html#if"><If></a></code> directive.</p> + +<p>Consider, for example, the common scenario where +<code class="directive">RewriteRule</code> is used to enforce a canonical +hostname, such as <code>www.example.com</code> instead of +<code>example.com</code>. This can be done using the <code class="directive"><a href="../mod/core.html#if"><If></a></code> directive, as shown here:</p> + +<pre class="prettyprint lang-config"><If "req('Host') != 'www.example.com'"> + Redirect "/" "http://www.example.com/" +</If></pre> + + +<p>This technique can be used to take actions based on any request +header, response header, or environment variable, replacing +<code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> in many common scenarios.</p> + +<p>See especially the <a href="../expr.html">expression evaluation +documentation</a> for a overview of what types of expressions you can +use in <code class="directive"><a href="../mod/core.html#if"><If></a></code> sections, +and in certain other directives.</p> + +</div></div> +<div class="bottomlang"> +<p><span>Available Languages: </span><a href="../en/rewrite/avoid.html" title="English"> en </a> | +<a href="../fr/rewrite/avoid.html" hreflang="fr" rel="alternate" title="Français"> fr </a></p> +</div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Libera.chat, or sent to our <a href="https://httpd.apache.org/lists.html">mailing lists</a>.</div> +<script type="text/javascript"><!--//--><![CDATA[//><!-- +var comments_shortname = 'httpd'; +var comments_identifier = 'http://httpd.apache.org/docs/2.4/rewrite/avoid.html'; +(function(w, d) { + if (w.location.hostname.toLowerCase() == "httpd.apache.org") { + d.write('<div id="comments_thread"><\/div>'); + var s = d.createElement('script'); + s.type = 'text/javascript'; + s.async = true; + s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; + (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); + } + else { + d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); + } +})(window, document); +//--><!]]></script></div><div id="footer"> +<p class="apache">Copyright 2023 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p> +<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- +if (typeof(prettyPrint) !== 'undefined') { + prettyPrint(); +} +//--><!]]></script> +</body></html>
\ No newline at end of file diff --git a/docs/manual/rewrite/avoid.html.fr.utf8 b/docs/manual/rewrite/avoid.html.fr.utf8 new file mode 100644 index 0000000..627777a --- /dev/null +++ b/docs/manual/rewrite/avoid.html.fr.utf8 @@ -0,0 +1,271 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr"><head> +<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" /> +<!-- + XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + This file is generated from xml source: DO NOT EDIT + XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX + --> +<title>Quand ne pas utiliser mod_rewrite - Serveur HTTP Apache Version 2.4</title> +<link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> +<link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> +<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" /> +<script src="../style/scripts/prettify.min.js" type="text/javascript"> +</script> + +<link href="../images/favicon.ico" rel="shortcut icon" /></head> +<body id="manual-page"><div id="page-header"> +<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossaire</a> | <a href="../sitemap.html">Plan du site</a></p> +<p class="apache">Serveur HTTP Apache Version 2.4</p> +<img alt="" src="../images/feather.png" /></div> +<div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div> +<div id="path"> +<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">Serveur HTTP</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.4</a> > <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>Quand ne pas utiliser mod_rewrite</h1> +<div class="toplang"> +<p><span>Langues Disponibles: </span><a href="../en/rewrite/avoid.html" hreflang="en" rel="alternate" title="English"> en </a> | +<a href="../fr/rewrite/avoid.html" title="Français"> fr </a></p> +</div> + + +<p>Ce document est un complément à la <a href="../mod/mod_rewrite.html">Documentation de référence</a> de +<code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>. Il décrit peut-être un des concepts les +plus importants à propos de <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> - à savoir, quand doit-on éviter +de l'utiliser.</p> + +<p><code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> doit être considéré comme un dernier recours, +lorsqu'aucune alternative n'est possible. Utiliser mod_rewrite lorsqu'il +existe des alternatives plus simples conduit à des configurations +confuses, fragiles, et difficiles à maintenir. La compréhension des +autres alternatives disponibles est une étape très importante sur le +chemin de la maîtrise de <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>.</p> + +<p>Vous devez vous attacher à comprendre le +fonctionnement des exemples, car la plupart d'entre eux ne +fonctionneront pas sur votre système si vous vous contentez de les +copier/coller dans vos fichiers de configuration.</p> + +<p>Le cas le plus courant dans lequel <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> est +l'outil approprié est la situation où la seule solution envisageable +nécessite l'accès aux fichiers de configuration du serveur, alors que +cet accès ne vous est pas accordé. Certaines directives de configuration +ne sont disponibles que dans le fichier de configuration du serveur. Si +vous ne pouvez agir que sur les fichiers .htaccess, vous devrez donc +vous tourner vers <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>.</p> + +</div> +<div id="quickview"><a href="https://www.apache.org/foundation/contributing.html" class="badge"><img src="https://www.apache.org/images/SupportApache-small.png" alt="Support Apache!" /></a><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#redirect">Redirection simple</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#alias">Alias d'URL</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#vhosts">Hébergement virtuel</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#proxy">Mandat simple</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#setenv">Test de variables d'environnement</a></li> +</ul><h3>Voir aussi</h3><ul class="seealso"><li><a href="../mod/mod_rewrite.html">Documentation du module mod_rewrite</a></li><li><a href="intro.html">Introduction à mod_rewrite</a></li><li><a href="remapping.html">Redirection et remise en +correspondance</a></li><li><a href="access.html">Contrôle d'accès</a></li><li><a href="vhosts.html">Serveurs virtuels</a></li><li><a href="proxy.html">Serveurs mandataires</a></li><li><a href="rewritemap.html">Utilisation de RewriteMap</a></li><li><a href="advanced.html">Techniques avancées</a></li><li><a href="#comments_section">Commentaires</a></li></ul></div> +<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="redirect" id="redirect">Redirection simple</a></h2> + + +<p><code class="module"><a href="../mod/mod_alias.html">mod_alias</a></code> fournit les directives <code class="directive"><a href="../mod/mod_alias.html#redirect">Redirect</a></code> et <code class="directive"><a href="../mod/mod_alias.html#redirectmatch">RedirectMatch</a></code> qui permettent de +rediriger une URL vers une autre. Plutôt que d'utiliser la directive +<code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> pour ce genre de +redirection simple d'une URL ou d'une classe d'URLs vers une autre, on +préfèrera l'utilisation de ces directives. En outre, avec +<code>RedirectMatch</code>, vous pouvez inclure une expression +rationnelle dans votre critère de redirection, ce qui vous permet de +bénéficier de nombreux avantages de la directive +<code>RewriteRule</code>.</p> + +<p>Une utilisation courante de la directive <code>RewriteRule</code> est +la redirection de toute une classe d'URLs. Par exemple, toutes les URLs +faisant référence au répertoire <code>/un</code> doivent être +redirigées vers <code>http://un.example.com/</code>, ou toutes les +requêtes <code>http</code> doivent être redirigées vers +<code>https</code>.</p> + +<p>Pour ce faire, il est préférable d'utiliser la directive +<code>Redirect</code>. Souvenez-vous que la directive +<code>Redirect</code> conserve les informations relatives au chemin. En +d'autres termes, la redirection d'une URL <code>/un</code> va aussi +rediriger toutes les URLs de niveaux inférieurs comme +<code>/un/deux.html</code> et <code>/un/trois/quatre.html</code>.</p> + +<p>Pour rediriger les URLs sous <code>/un</code> vers +<code>http://un.example.com/</code>, utilisez cette définition :</p> + +<pre class="prettyprint lang-config">Redirect /one/ http://one.example.com/</pre> + + +<p>Pour rediriger un nom d'hôte vers un autre nom d'hôte, par exemple +<code>example.com</code> vers <code>www.example.com</code>, voir la +méthode <a href="remapping.html#canonicalhost">Noms d'hôtes canoniques</a>.</p> + +<p>Pour rediriger les URLs <code>http</code> vers <code>https</code>, +utilisez cette définition :</p> + +<pre class="prettyprint lang-config"><VirtualHost *:80> +ServerName www.example.com +Redirect "/" "https://www.example.com/" +</VirtualHost> + +<VirtualHost *:443> +ServerName www.example.com +# ... insérer ici la configuration SSL +</VirtualHost></pre> + + +<p>L'utilisation de la directive <code>RewriteRule</code> pour accomplir +cette tâche peut se justifier s'il existe d'autres directives +<code>RewriteRule</code> dans la même portée. En effet, lorsque des +directives <code>Redirect</code> et <code>RewriteRule</code> se trouvent +dans la même portée, les directives <code>RewriteRule</code> sont +exécutées en premier, sans tenir compte de leur ordre d'apparition dans +le fichier de configuration.</p> + +<p>Dans le cas de la redirection <em>http-vers-https</em>, l'utilisation +de règles <code>RewriteRule</code> se justifie si vous n'avez pas accès +au fichier de configuration principal, et devez donc accomplir cette +tâche au sein d'un fichier <code>.htaccess</code>.</p> + +</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="alias" id="alias">Alias d'URL</a></h2> +<p>La directive <code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code> permet +de mettre en correspondance un URI avec un répertoire, ce dernier étant +en général situé en dehors de l'arborescence définie par la directive +<code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>. Bien qu'il soit +possible d'effectuer cette mise en correspondance avec +<code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>, il est préférable d'utiliser la directive +<code class="directive"><a href="../mod/mod_alias.html#alias">Alias</a></code> pour des raisons de simplicité +et de performances.</p> + +<div class="example"><h3>Utilisation de la directive Alias</h3><pre class="prettyprint lang-config">Alias "/cats" "/var/www/virtualhosts/felines/htdocs"</pre> +</div> + +<p> +Pour effectuer cette mise en correspondance, <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> +s'impose si vous n'avez pas accès aux fichiers de configuration du +serveur. En effet, la directive Alias ne peut pas être utilisée dans un +fichier <code>.htaccess</code>, mais seulement dans un contexte de +serveur principal ou de serveur virtuel. +</p> + +<p>En outre, vous pouvez arriver au même résultat avec les liens +symboliques, pourvu que <code>Options FollowSymLinks</code> soit activé +sur votre serveur.</p> +</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="vhosts" id="vhosts">Hébergement virtuel</a></h2> +<p>Bien qu'il soit possible de gérer les <a href="vhosts.html">serveurs +virtuels avec mod_rewrite</a>, il s'agit rarement de la bonne méthode. +Il est pratiquement toujours préférable de créer des blocs +<code class="directive"><a href="../mod/core.html#virtualhost"><VirtualHost></a></code> individuels. +Dans l'éventualité où vous devez gérer +un grand nombre de serveurs virtuels, vous devez vous tourner vers +<code class="module"><a href="../mod/mod_vhost_alias.html">mod_vhost_alias</a></code> pour créer ces serveurs +automatiquement.</p> + +<p>Il est aussi possible d'utiliser des modules comme <code class="module"><a href="../mod/mod_macro.html">mod_macro</a></code> pour +créer un grand nombre de serveurs virtuels dynamiquement.</p> + +<p>L'utilisation de <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> pour la création de +serveurs virtuels peut se révéler appropriée si votre service +d'hébergement ne vous permet pas d'accéder aux fichiers de configuration +du serveur, et que vous soyez par conséquent obligé de passer par les +fichiers <code>.htaccess</code>.</p> + +<p>Voir le document <a href="vhosts.html">création de serveurs virtuels +avec mod_rewrite</a> pour plus de détails sur la manière d'y parvenir si +cela semble être tout de même la meilleure approche.</p> + +</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="proxy" id="proxy">Mandat simple</a></h2> + +<p>La directive <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> fournit +le drapeau <a href="flags.html#flag_p">[P]</a> qui permet de faire passer les URIs +réécrits par <code class="module"><a href="../mod/mod_proxy.html">mod_proxy</a></code>.</p> + +<pre class="prettyprint lang-config">RewriteRule "^/?images(.*)" "http://serveur-images.local/images$1" [P]</pre> + + +<p>Cependant, dans les nombreux cas où aucune correspondance au modèle +n'est vraiment nécessaire, comme dans l'exemple ci-dessus, il est +préférable d'utiliser la directive <code class="directive"><a href="../mod/mod_proxy.html#proxypass">ProxyPass</a></code>. L'exemple précédent pourrait +être remplacé par :</p> + +<pre class="prettyprint lang-config">ProxyPass "/images/" "http://serveur-images.local/images/"</pre> + + +<p>Que vous utilisiez <code class="directive"><a href="../mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> ou <code class="directive"><a href="../mod/mod_proxy.html#proxypass">ProxyPass</a></code>, vous devrez dans tous les cas +utiliser aussi la directive <code class="directive"><a href="../mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code> pour intercepter les +redirections en provenance du serveur d'arrière-plan :</p> + +<pre class="prettyprint lang-config">ProxyPassReverse "/images/" "http://serveur-images.local/images/"</pre> + + +<p>Vous devrez cependant tout de même utiliser <code>RewriteRule</code> +lorsque d'autres <code>RewriteRule</code>s se trouvent dans la même portée, +car elles agissent en général avant les directives +<code>ProxyPass</code>, et peuvent ainsi les court-circuiter.</p> + +</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="setenv" id="setenv">Test de variables d'environnement</a></h2> + +<p><code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> est souvent utilisé pour effectuer une +action en fonction de la présence ou de l'absence d'une variable +d'environnement particulière ou d'un en-tête de requête, ce qui peut +être accompli de manière plus efficace via la directive <code class="directive"><a href="../mod/core.html#if"><If></a></code>.</p> + +<p>Considérons par exemple le scénario courant où la directive +<code class="directive">RewriteRule</code> est utilisée pour forcer un nom +d'hôte canonique, tel que <code>www.example.com</code> au lieu de +<code>example.com</code>. Il est possible d'utiliser à la place la +directive <code class="directive"><a href="../mod/core.html#if"><If></a></code> comme +suit :</p> + +<pre class="prettyprint lang-config"><If "req('Host') != 'www.example.com'"> + Redirect "/" "http://www.example.com" +</If></pre> + + +<p>On peut utiliser cette technique dans de nombreux scénarios courant +pour remplacer <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> pour effectuer des actions +en fonction d'en-têtes de requêtes ou de réponses, ou de variables +d'environnement.</p> + +<p>Voir en particulier la <a href="../expr.html">documentation sur +l'évaluation des expressions</a> pour une vue d'ensemble des types +d'expressions que vous pouvez utiliser dans les sections <code class="directive"><a href="../mod/core.html#if"><If></a></code>, +ainsi que dans certaines directives.</p> + +</div></div> +<div class="bottomlang"> +<p><span>Langues Disponibles: </span><a href="../en/rewrite/avoid.html" hreflang="en" rel="alternate" title="English"> en </a> | +<a href="../fr/rewrite/avoid.html" title="Français"> fr </a></p> +</div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Commentaires</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Libera.chat, or sent to our <a href="https://httpd.apache.org/lists.html">mailing lists</a>.</div> +<script type="text/javascript"><!--//--><![CDATA[//><!-- +var comments_shortname = 'httpd'; +var comments_identifier = 'http://httpd.apache.org/docs/2.4/rewrite/avoid.html'; +(function(w, d) { + if (w.location.hostname.toLowerCase() == "httpd.apache.org") { + d.write('<div id="comments_thread"><\/div>'); + var s = d.createElement('script'); + s.type = 'text/javascript'; + s.async = true; + s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; + (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); + } + else { + d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); + } +})(window, document); +//--><!]]></script></div><div id="footer"> +<p class="apache">Copyright 2023 The Apache Software Foundation.<br />Autorisé sous <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p> +<p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossaire</a> | <a href="../sitemap.html">Plan du site</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- +if (typeof(prettyPrint) !== 'undefined') { + prettyPrint(); +} +//--><!]]></script> +</body></html>
\ No newline at end of file |