diff options
Diffstat (limited to 'docs/manual/rewrite/remapping.html.en')
-rw-r--r-- | docs/manual/rewrite/remapping.html.en | 111 |
1 files changed, 38 insertions, 73 deletions
diff --git a/docs/manual/rewrite/remapping.html.en b/docs/manual/rewrite/remapping.html.en index f2cc2014..7bdc1449 100644 --- a/docs/manual/rewrite/remapping.html.en +++ b/docs/manual/rewrite/remapping.html.en @@ -9,7 +9,7 @@ <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.js" type="text/javascript"> +<script src="../style/scripts/prettify.min.js" type="text/javascript"> </script> <link href="../images/favicon.ico" rel="shortcut icon" /></head> @@ -75,10 +75,8 @@ configuration.</div> <p>We rewrite the old URL to the new one internally via the following rule:</p> -<pre class="prettyprint lang-config"> -RewriteEngine on -RewriteRule ^<strong>/foo</strong>\.html$ <strong>/bar</strong>.html [PT] -</pre> +<pre class="prettyprint lang-config">RewriteEngine on +RewriteRule ^<strong>/foo</strong>\.html$ <strong>/bar</strong>.html [PT]</pre> </dd> </dl> @@ -107,10 +105,8 @@ RewriteRule ^<strong>/foo</strong>\.html$ <strong>/bar</strong>.html [PT] <p>We force a HTTP redirect to the new URL which leads to a change of the browsers and thus the users view:</p> -<pre class="prettyprint lang-config"> -RewriteEngine on -RewriteRule ^<strong>/foo</strong>\.html$ <strong>bar</strong>.html [<strong>R</strong>] -</pre> +<pre class="prettyprint lang-config">RewriteEngine on +RewriteRule ^<strong>/foo</strong>\.html$ <strong>bar</strong>.html [<strong>R</strong>]</pre> </dd> @@ -151,18 +147,15 @@ RewriteRule ^<strong>/foo</strong>\.html$ <strong>bar</strong>.html [<stron <pre class="prettyprint lang-config">#With mod_rewrite RewriteEngine on -RewriteRule ^/docs/(.+) http://new.example.com/docs/$1 [R,L] -</pre> +RewriteRule ^/docs/(.+) http://new.example.com/docs/$1 [R,L]</pre> <pre class="prettyprint lang-config">#With RedirectMatch -RedirectMatch ^/docs/(.*) http://new.example.com/docs/$1 -</pre> +RedirectMatch ^/docs/(.*) http://new.example.com/docs/$1</pre> <pre class="prettyprint lang-config">#With Redirect -Redirect /docs/ http://new.example.com/docs/ -</pre> +Redirect /docs/ http://new.example.com/docs/</pre> </dd> </dl> @@ -193,11 +186,9 @@ Redirect /docs/ http://new.example.com/docs/ internally leads to the invocation of <code>/~quux/foo.cgi</code>.</p> -<pre class="prettyprint lang-config"> -RewriteEngine on +<pre class="prettyprint lang-config">RewriteEngine on RewriteBase /~quux/ -RewriteRule ^foo\.html$ foo.cgi [H=<strong>cgi-script</strong>] -</pre> +RewriteRule ^foo\.html$ foo.cgi [H=<strong>cgi-script</strong>]</pre> </dd> </dl> @@ -225,8 +216,7 @@ RewriteRule ^foo\.html$ foo.cgi [H=<strong>cgi-script</strong>] existence of the new extension. If it exists, we take that name, else we rewrite the URL to its original state.</p> -<pre class="prettyprint lang-config"> -# backward compatibility ruleset for +<pre class="prettyprint lang-config"># backward compatibility ruleset for # rewriting document.html to document.php # when and only when document.php exists <Directory /var/www/htdocs> @@ -236,8 +226,7 @@ RewriteRule ^foo\.html$ foo.cgi [H=<strong>cgi-script</strong>] RewriteCond $1.php -f RewriteCond $1.html !-f RewriteRule ^(.*).html$ $1.php -</Directory> -</pre> +</Directory></pre> </dd> @@ -285,8 +274,7 @@ but rather uses the <code class="directive"><a href="../mod/mod_alias.html#redir directive placed in a virtual host for the non-canonical hostname(s).</p> -<pre class="prettyprint lang-config"> -<VirtualHost *:80> +<pre class="prettyprint lang-config"><VirtualHost *:80> ServerName undesired.example.com ServerAlias example.com notthis.example.com @@ -295,29 +283,24 @@ hostname(s).</p> <VirtualHost *:80> ServerName www.example.com -</VirtualHost> -</pre> +</VirtualHost></pre> <p>You can alternatively accomplish this using the <code class="directive"><a href="../mod/core.html#if"><If></a></code> directive:</p> -<pre class="prettyprint lang-config"> -<If "%{HTTP_HOST} != 'www.example.com'"> +<pre class="prettyprint lang-config"><If "%{HTTP_HOST} != 'www.example.com'"> Redirect / http://www.example.com/ -</If> -</pre> +</If></pre> <p>Or, for example, to redirect a portion of your site to HTTPS, you might do the following:</p> -<pre class="prettyprint lang-config"> -<If "%{SERVER_PROTOCOL} != 'HTTPS'"> +<pre class="prettyprint lang-config"><If "%{SERVER_PROTOCOL} != 'HTTPS'"> Redirect /admin/ https://www.example.com/admin/ -</If> -</pre> +</If></pre> <p>If, for whatever reason, you still want to use <code>mod_rewrite</code> @@ -325,20 +308,16 @@ might do the following:</p> you might use one of the recipes below.</p> <p>For sites running on a port other than 80:</p> -<pre class="prettyprint lang-config"> -RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] +<pre class="prettyprint lang-config">RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteCond %{HTTP_HOST} !^$ RewriteCond %{SERVER_PORT} !^80$ -RewriteRule ^/?(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R,NE] -</pre> +RewriteRule ^/?(.*) http://www.example.com:%{SERVER_PORT}/$1 [L,R,NE]</pre> <p>And for a site running on port 80</p> -<pre class="prettyprint lang-config"> -RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] +<pre class="prettyprint lang-config">RewriteCond %{HTTP_HOST} !^www\.example\.com [NC] RewriteCond %{HTTP_HOST} !^$ -RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE] -</pre> +RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE]</pre> <p> @@ -348,11 +327,9 @@ RewriteRule ^/?(.*) http://www.example.com/$1 [L,R,NE] <strong>example.com</strong>, you could use the following recipe:</p> -<pre class="prettyprint lang-config"> -RewriteCond %{HTTP_HOST} !^www\. [NC] +<pre class="prettyprint lang-config">RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} !^$ -RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE] -</pre> +RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE]</pre> <p>These rulesets will work either in your main server configuration @@ -383,8 +360,7 @@ RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE] resource, and, if not finding it in either place, will attempt to just serve it out of the location requested.</p> -<pre class="prettyprint lang-config"> -RewriteEngine on +<pre class="prettyprint lang-config">RewriteEngine on # first try to find it in dir1/... # ...and if found stop and be happy: @@ -398,8 +374,7 @@ RewriteRule ^(.+) %{DOCUMENT_ROOT}/<strong>dir2</strong>/$1 [L] # else go on for other Alias or ScriptAlias directives, # etc. -RewriteRule ^ - [PT] -</pre> +RewriteRule ^ - [PT]</pre> </dd> </dl> @@ -428,13 +403,11 @@ RewriteRule ^ - [PT] <p>We'll use a <code class="directive"><a href="../mod/mod_rewrite.html#rewritemap">RewriteMap</a></code> directive to build a list of servers that we wish to use.</p> -<pre class="prettyprint lang-config"> -HostnameLookups on +<pre class="prettyprint lang-config">HostnameLookups on RewriteEngine on RewriteMap multiplex txt:/path/to/map.mirrors RewriteCond %{REMOTE_HOST} ([a-z]+)$ [NC] -RewriteRule ^/(.*)$ ${multiplex:<strong>%1</strong>|http://www.example.com/}$1 [R,L] -</pre> +RewriteRule ^/(.*)$ ${multiplex:<strong>%1</strong>|http://www.example.com/}$1 [R,L]</pre> <div class="example"><p><code> @@ -489,16 +462,14 @@ com http://www.example.com/<br /> All other browsers receive page <code>foo.32.html</code>. This is done with the following ruleset:</p> -<pre class="prettyprint lang-config"> -RewriteCond %{HTTP_USER_AGENT} ^<strong>Mozilla/3</strong>.* +<pre class="prettyprint lang-config">RewriteCond %{HTTP_USER_AGENT} ^<strong>Mozilla/3</strong>.* RewriteRule ^foo\.html$ foo.<strong>NS</strong>.html [<strong>L</strong>] RewriteCond %{HTTP_USER_AGENT} ^Lynx/ [OR] RewriteCond %{HTTP_USER_AGENT} ^Mozilla/[12] RewriteRule ^foo\.html$ foo.<strong>20</strong>.html [<strong>L</strong>] -RewriteRule ^foo\.html$ foo.<strong>32</strong>.html [<strong>L</strong>] -</pre> +RewriteRule ^foo\.html$ foo.<strong>32</strong>.html [<strong>L</strong>]</pre> </dd> </dl> @@ -539,7 +510,7 @@ RewriteRule ^foo\.html$ foo.<strong>32</strong>.html [<strong>L This should really be accomplished with Redirect or RedirectMatch directives: - <pre class="prettyprint lang-config"> RedirectMatch ^/(puppies|canines)/(.*) /dogs/$2 </pre> + <pre class="prettyprint lang-config">RedirectMatch ^/(puppies|canines)/(.*) /dogs/$2</pre> </dd> </dl> @@ -569,10 +540,8 @@ using the following ruleset:</p> <code>/about/</code>: </p> -<pre class="prettyprint lang-config"> -RewriteEngine on -RewriteRule ^/$ /about/ [<strong>R</strong>] -</pre> +<pre class="prettyprint lang-config">RewriteEngine on +RewriteRule ^/$ /about/ [<strong>R</strong>]</pre> <p>Note that this can also be handled using the <code class="directive"><a href="../mod/mod_alias.html#redirectmatch">RedirectMatch</a></code> directive:</p> @@ -606,26 +575,22 @@ that should go to an existing resource such as an image, or a css file.</dd> <dd> <p>As of version 2.2.16, you should use the <code class="directive"><a href="../mod/mod_dir.html#fallbackresource">FallbackResource</a></code> directive for this:</p> -<pre class="prettyprint lang-config"> -<Directory /var/www/my_blog> +<pre class="prettyprint lang-config"><Directory /var/www/my_blog> FallbackResource index.php -</Directory> -</pre> +</Directory></pre> <p>However, in earlier versions of Apache, or if your needs are more complicated than this, you can use a variation of the following rewrite set to accomplish the same thing:</p> -<pre class="prettyprint lang-config"> -<Directory /var/www/my_blog> +<pre class="prettyprint lang-config"><Directory /var/www/my_blog> RewriteBase /my_blog RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-f RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-d RewriteRule ^ index.php [PT] -</Directory> -</pre> +</Directory></pre> <p>If, on the other hand, you wish to pass the requested URI as a query @@ -663,7 +628,7 @@ var comments_identifier = 'http://httpd.apache.org/docs/2.4/rewrite/remapping.ht } })(window, document); //--><!]]></script></div><div id="footer"> -<p class="apache">Copyright 2013 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="apache">Copyright 2014 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(); |