10705fbc225dcf590c9ba24a4f04de221358060arbowen<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
6896b3498e144d33f374efe93e6bab2669af535fnd<!-- $LastChangedRevision$ -->
10705fbc225dcf590c9ba24a4f04de221358060arbowen Licensed to the Apache Software Foundation (ASF) under one or more
10705fbc225dcf590c9ba24a4f04de221358060arbowen contributor license agreements. See the NOTICE file distributed with
10705fbc225dcf590c9ba24a4f04de221358060arbowen this work for additional information regarding copyright ownership.
10705fbc225dcf590c9ba24a4f04de221358060arbowen The ASF licenses this file to You under the Apache License, Version 2.0
10705fbc225dcf590c9ba24a4f04de221358060arbowen (the "License"); you may not use this file except in compliance with
10705fbc225dcf590c9ba24a4f04de221358060arbowen the License. You may obtain a copy of the License at
10705fbc225dcf590c9ba24a4f04de221358060arbowen Unless required by applicable law or agreed to in writing, software
10705fbc225dcf590c9ba24a4f04de221358060arbowen distributed under the License is distributed on an "AS IS" BASIS,
10705fbc225dcf590c9ba24a4f04de221358060arbowen WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10705fbc225dcf590c9ba24a4f04de221358060arbowen See the License for the specific language governing permissions and
10705fbc225dcf590c9ba24a4f04de221358060arbowen limitations under the License.
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim<p>This document supplements the <module>mod_rewrite</module>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<a href="/mod/mod_rewrite.html">reference documentation</a>. It describes
10705fbc225dcf590c9ba24a4f04de221358060arbowenhow to use the RewriteRule's [P] flag to proxy content to another server.
10705fbc225dcf590c9ba24a4f04de221358060arbowenA number of recipes are provided that describe common scenarios.</p>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<seealso><a href="/mod/mod_rewrite.html">Module documentation</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<seealso><a href="intro.html">mod_rewrite introduction</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<seealso><a href="remapping.html">Redirection and remapping</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<seealso><a href="access.html">Controlling access</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<seealso><a href="vhosts.html">Virtual hosts</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<!--<seealso><a href="proxy.html">Proxying</a></seealso>-->
3723c5ef4beec0403b4daa6c64fc0a8f53541018rbowen<seealso><a href="rewritemap.html">Using RewriteMap</a></seealso>
53abc235688d883cfa15cdfec354ba03128f357arbowen<seealso><a href="advanced.html">Advanced techniques</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen<seealso><a href="avoid.html">When not to use mod_rewrite</a></seealso>
10705fbc225dcf590c9ba24a4f04de221358060arbowen mod_rewrite provides the [P] flag, which allows URLs to be passed,
10705fbc225dcf590c9ba24a4f04de221358060arbowen via mod_proxy, to another server. Two examples are given here. In
10705fbc225dcf590c9ba24a4f04de221358060arbowen one example, a URL is passed directly to another server, and served
10705fbc225dcf590c9ba24a4f04de221358060arbowen as though it were a local URL. In the other example, we proxy
10705fbc225dcf590c9ba24a4f04de221358060arbowen missing content to a back-end server.</p>
10705fbc225dcf590c9ba24a4f04de221358060arbowen <p>To simply map a URL to another server, we use the [P] flag, as
10705fbc225dcf590c9ba24a4f04de221358060arbowen follows:</p>
0a0fd048f54df3e9053942466292da579524c1fdhumbedoohRewriteEngine on
5d01f40ffd657dd2ac567aacd93cabd162ddfa79coarRewriteBase "/products/"
5d01f40ffd657dd2ac567aacd93cabd162ddfa79coarRewriteRule "^widget/(.*)$" "http://product.example.com/widget/$1" [P]
2fae9d127f7143fabe8f73958eb9bde31df17d41coarProxyPassReverse "/products/widget/" "http://product.example.com/widget/"
10705fbc225dcf590c9ba24a4f04de221358060arbowen <p>In the second example, we proxy the request only if we can't find
10705fbc225dcf590c9ba24a4f04de221358060arbowen the resource locally. This can be very useful when you're migrating
10705fbc225dcf590c9ba24a4f04de221358060arbowen from one server to another, and you're not sure if all the content
10705fbc225dcf590c9ba24a4f04de221358060arbowen has been migrated yet.</p>
5d01f40ffd657dd2ac567aacd93cabd162ddfa79coarRewriteCond "%{REQUEST_FILENAME}" !-f
5d01f40ffd657dd2ac567aacd93cabd162ddfa79coarRewriteCond "%{REQUEST_FILENAME}" !-d
5d01f40ffd657dd2ac567aacd93cabd162ddfa79coarRewriteRule "^/(.*)" "http://old.example.com/$1" [P]
2fae9d127f7143fabe8f73958eb9bde31df17d41coarProxyPassReverse "/" "http://old.example.com/"
10705fbc225dcf590c9ba24a4f04de221358060arbowen module="mod_proxy">ProxyPassReverse</directive> directive to ensure
10705fbc225dcf590c9ba24a4f04de221358060arbowen that any redirects issued by the backend are correctly passed on to
10705fbc225dcf590c9ba24a4f04de221358060arbowen the client.</p>
10705fbc225dcf590c9ba24a4f04de221358060arbowen module="mod_proxy">ProxyPass</directive> or <directive
be882eb3b57b3e6d2995f7a9aea610eefb92d836rbowen module="mod_proxy">ProxyPassMatch</directive> whenever possible in
10705fbc225dcf590c9ba24a4f04de221358060arbowen preference to mod_rewrite.</p>
860b4efe27e7c1c9a2bf5c872b29c90f76849b51jim</manualpage>