proxy.xml revision 53abc235688d883cfa15cdfec354ba03128f357a
7abe86bacd7821fb83a784398037defc64060a2emanoj<?xml version="1.0" encoding="UTF-8" ?>
7abe86bacd7821fb83a784398037defc64060a2emanoj<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<!-- $LastChangedRevision$ -->
809c98e396829d27f2d9efc0c27f7bb1294381bcgstein
7abe86bacd7821fb83a784398037defc64060a2emanoj<!--
cd47196ef7dd7647418fa9b9cb8297cfa614c100rbb Licensed to the Apache Software Foundation (ASF) under one or more
7bb9fddff37df5cde21b7c4880360f5199875874trawick contributor license agreements. See the NOTICE file distributed with
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz this work for additional information regarding copyright ownership.
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz The ASF licenses this file to You under the Apache License, Version 2.0
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz (the "License"); you may not use this file except in compliance with
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz the License. You may obtain a copy of the License at
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz http://www.apache.org/licenses/LICENSE-2.0
5f4f0143cfe4e4a74195441b3c9dba4662a7788dniq
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz Unless required by applicable law or agreed to in writing, software
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz distributed under the License is distributed on an "AS IS" BASIS,
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz See the License for the specific language governing permissions and
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz limitations under the License.
7825bb798c5cdbed5865904896146aea6da1fd52bnicholes-->
7825bb798c5cdbed5865904896146aea6da1fd52bnicholes
7825bb798c5cdbed5865904896146aea6da1fd52bnicholes<manualpage metafile="proxy.xml.meta">
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz <parentdocument href="./">Rewrite</parentdocument>
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<title>Using mod_rewrite for Proxying</title>
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<summary>
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<p>This document supplements the <module>mod_rewrite</module>
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<a href="/mod/mod_rewrite.html">reference documentation</a>. It describes
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantzhow to use the RewriteRule's [P] flag to proxy content to another server.
84572252cfafd33c91d893b34dec34fcbca34371ndA number of recipes are provided that describe common scenarios.</p>
6c47a7d40935c5508868904cba1e87ca783ec386niq
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz</summary>
480706fbb16436bfdff23c83c8993875ae7ece92minfrin<seealso><a href="/mod/mod_rewrite.html">Module documentation</a></seealso>
480706fbb16436bfdff23c83c8993875ae7ece92minfrin<seealso><a href="intro.html">mod_rewrite introduction</a></seealso>
480706fbb16436bfdff23c83c8993875ae7ece92minfrin<seealso><a href="remapping.html">Redirection and remapping</a></seealso>
480706fbb16436bfdff23c83c8993875ae7ece92minfrin<seealso><a href="access.html">Controlling access</a></seealso>
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<seealso><a href="vhosts.html">Virtual hosts</a></seealso>
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<!--<seealso><a href="proxy.html">Proxying</a></seealso>-->
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<seealso><a href="rewritemap.html">Using RewriteMap</a></seealso>
aefffd0b370de6f499564ff7e0576c931a53fccdstoddard<seealso><a href="advanced.html">Advanced techniques</a></seealso>
b4a287513d176e4355dd56ea47b27228e0e5d75fjerenkrantz<seealso><a href="avoid.html">When not to use mod_rewrite</a></seealso>
322b350d0f1ac750b112ec15481a33efc92d182cjerenkrantz
e9f8410b788ef1e6f1baed6c706ffdf3da395a16jerenkrantz<section id="dynamic-proxy">
e9f8410b788ef1e6f1baed6c706ffdf3da395a16jerenkrantz
7416a4d524cc7456c90a155e06fae5ac6c2d0288trawick <title>Proxying Content with mod_rewrite</title>
7416a4d524cc7456c90a155e06fae5ac6c2d0288trawick
7416a4d524cc7456c90a155e06fae5ac6c2d0288trawick <dl>
7416a4d524cc7456c90a155e06fae5ac6c2d0288trawick <dt>Description:</dt>
7416a4d524cc7456c90a155e06fae5ac6c2d0288trawick
7416a4d524cc7456c90a155e06fae5ac6c2d0288trawick <dd>
855aa233fcb7b51d738fca5c36585646ae1960c3jerenkrantz <p>
7abe86bacd7821fb83a784398037defc64060a2emanoj mod_rewrite provides the [P] flag, which allows URLs to be passed,
c803b0d84b48f151504b87ec3f196cb433149592rbb via mod_proxy, to another server. Two examples are given here. In
one example, a URL is passed directly to another server, and served
as though it were a local URL. In the other example, we proxy
missing content to a back-end server.</p>
</dd>
<dt>Solution:</dt>
<dd>
<p>To simply map a URL to another server, we use the [P] flag, as
follows:</p>
<example>
RewriteEngine on<br />
RewriteBase /products/<br />
RewriteRule ^<strong>widget/</strong>(.*)$ <strong>http://product.example.com/widget/</strong>$1 [<strong>P</strong>]<br />
ProxyPassReverse /products/widget/ http://product.example.com/widget/
</example>
<p>In the second example, we proxy the request only if we can't find
the resource locally. This can be very useful when you're migrating
from one server to another, and you're not sure if all the content
has been migrated yet.</p>
<example>
RewriteCond %{REQUEST_FILENAME} <strong>!-f</strong><br />
RewriteCond %{REQUEST_FILENAME} <strong>!-d</strong><br />
RewriteRule ^/(.*) http://<strong>old</strong>.example.com/$1 [<strong>P</strong>]<br />
ProxyPassReverse / http://old.example.com/
</example>
</dd>
<dt>Discussion:</dt>
<dd><p>In each case, we add a <directive
module="mod_proxy">ProxyPassReverse</directive> directive to ensure
that any redirects issued by the backend are correctly passed on to
the client.</p>
<p>Consider using either <directive
module="mod_proxy">ProxyPass</directive> or <directive
module="mod_rewrite">ProxyPassMatch</directive> whenever possible in
preference to mod_rewrite.</p>
</dd>
</dl>
</section>
</manualpage>