1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 This file is generated from xml source: DO NOT EDIT
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
8 <title>Using mod_rewrite for Proxying - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
13 <body id="manual-page"><div id="page-header">
14 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
15 <p class="apache">Apache HTTP Server Version 2.3</p>
16 <img alt="" src="../images/feather.gif" /></div>
17 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
19 <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.3</a> > <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>Using mod_rewrite for Proxying</h1>
21 <p><span>Available Languages: </span><a href="../en/rewrite/proxy.html" title="English"> en </a></p>
25 <p>This document supplements the <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>
26 <a href="../mod/mod_rewrite.html">reference documentation</a>. It describes
27 how to use the RewriteRule's [P] flag to proxy content to another server.
28 A number of recipes are provided that describe common scenarios.</p>
31 <div id="quickview"><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="rewritemap.html">RewriteMap</a></li><li><a href="advanced.html">Advanced techniques and tricks</a></li><li><a href="avoid.html">When not to use mod_rewrite</a></li></ul></div>
32 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
34 <h2><a name="dynamic-proxy" id="dynamic-proxy">Proxying Content with mod_rewrite</a></h2>
43 mod_rewrite provides the [P] flag, which allows URLs to be passed,
44 via mod_proxy, to another server. Two examples are given here. In
45 one example, a URL is passed directly to another server, and served
46 as though it were a local URL. In the other example, we proxy
47 missing content to a back-end server.</p>
53 <p>To simply map a URL to another server, we use the [P] flag, as
56 <div class="example"><pre>
58 RewriteBase /products/
59 RewriteRule ^<strong>widget/</strong>(.*)$ <strong>http://product.example.com/widget/</strong>$1 [<strong>P</strong>]
60 ProxyPassReverse /products/widget/ http://product.example.com/widget/
63 <p>In the second example, we proxy the request only if we can't find
64 the resource locally. This can be very useful when you're migrating
65 from one server to another, and you're not sure if all the content
66 has been migrated yet.</p>
68 <div class="example"><pre>
69 RewriteCond %{REQUEST_FILENAME} <strong>!-f</strong>
70 RewriteCond %{REQUEST_FILENAME} <strong>!-d</strong>
71 RewriteRule ^/(.*) http://<strong>old</strong>.example.com$1 [<strong>P</strong>]
72 ProxyPassReverse / http://old.example.com/
78 <dd><p>In each case, we add a <code class="directive"><a href="../mod/mod_proxy.html#proxypassreverse">ProxyPassReverse</a></code> directive to ensure
79 that any redirects issued by the backend are correctly passed on to
82 <p>Consider using either <code class="directive"><a href="../mod/mod_proxy.html#proxypass">ProxyPass</a></code> or <code class="directive"><a href="../mod/mod_rewrite.html#proxypassmatch">ProxyPassMatch</a></code> whenever possible in
83 preference to mod_rewrite.</p>
88 <div class="bottomlang">
89 <p><span>Available Languages: </span><a href="../en/rewrite/proxy.html" title="English"> en </a></p>
90 </div><div id="footer">
91 <p class="apache">Copyright 2010 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>
92 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>