advanced.html.en revision b0306ceedec510a7b4ebe3a1b70c366bf5f2727c
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<?xml version="1.0" encoding="ISO-8859-1"?>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen This file is generated from xml source: DO NOT EDIT
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen -->
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<title>When not to use mod_rewrite - Apache HTTP Server</title>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<link href="/images/favicon.ico" rel="shortcut icon" /></head>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<body id="manual-page"><div id="page-header">
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<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>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<p class="apache">Apache HTTP Server Version 2.3</p>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<img alt="" src="/images/feather.gif" /></div>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="/images/left.gif" /></a></div>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<div id="path">
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.3</a> &gt; <a href="./">Rewrite</a></div><div id="page-content"><div id="preamble"><h1>When not to use mod_rewrite</h1>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<div class="toplang">
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<p><span>Available Languages: </span><a href="/en/rewrite/avoid.html" title="English">&nbsp;en&nbsp;</a></p>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen</div>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<p>This document supplements the <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<a href="/mod_rewrite.html">reference documentation</a>. It provides
b630661b71a5495a95831a05a6a2299fb1c7c771rbowena few advanced techniques and tricks using mod_rewrite.</p>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<div class="warning">Note that many of these examples won't work unchanged in your
b630661b71a5495a95831a05a6a2299fb1c7c771rbowenparticular server configuration, so it's important that you understand
b630661b71a5495a95831a05a6a2299fb1c7c771rbowenthem, rather than merely cutting and pasting the examples into your
b630661b71a5495a95831a05a6a2299fb1c7c771rbowenconfiguration.</div>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen</div>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen<div id="quickview"><ul id="toc"><li><img alt="" src="/images/down.gif" /> <a href="#sharding">URL-based sharding accross multiple backends</a></li>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen<li><img alt="" src="/images/down.gif" /> <a href="#on-the-fly-content">On-the-fly Content-Regeneration</a></li>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen</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></ul></div>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen<div class="section">
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen<h2><a name="sharding" id="sharding">URL-based sharding accross multiple backends</a></h2>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <dl>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <dt>Description:</dt>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <dd>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <p>A common technique for distributing the burden of
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen server load or storage space is called "sharding".
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen When using this method, a front-end server will use the
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen url to consistently "shard" users or objects to separate
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen backend servers.</p>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen </dd>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <dt>Solution:</dt>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <dd>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <p>A mapping is maintained, from users to target servers, in
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen external map files. They look like:</p>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen<div class="example"><pre>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowenuser1 physical_host_of_user1
1525d3506d73644ae695624f16b15cc73cc1c7acrbowenuser2 physical_host_of_user2
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen: :
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen</pre></div>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <p>We put this into a <code>map.users-to-hosts</code> file. The
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen aim is to map;</p>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen<div class="example"><pre>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen/u/user1/anypath
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen</pre></div>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <p>to</p>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen<div class="example"><pre>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowenhttp://physical_host_of_user1/u/user/anypath
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen</pre></div>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen <p>thus every URL path need not be valid on every backend physical
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen host. The following ruleset does this for us with the help of the map
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen files assuming that server0 is a default server which will be used if
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen a user has no entry in the map):</p>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen<div class="example"><pre>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowenRewriteEngine on
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowenRewriteMap users-to-hosts txt:/path/to/map.users-to-hosts
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowenRewriteRule ^/u/<strong>([^/]+)</strong>/?(.*) http://<strong>${users-to-hosts:$1|server0}</strong>/u/$1/$2
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen</pre></div>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen </dd>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen </dl>
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen<div class="section">
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen<h2><a name="on-the-fly-content" id="on-the-fly-content">On-the-fly Content-Regeneration</a></h2>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <dl>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <dt>Description:</dt>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <dd>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <p>We wish to dynamically generate content, but store it
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen statically once it is generated. This rule will check for the
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen existence of the static file, and if it's not there, generate
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen it. The static files can be removed periodically, if desired (say,
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen via cron) and will be regenerated on demand.</p>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen </dd>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <dt>Solution:</dt>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <dd>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen This is done via the following ruleset:
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen<div class="example"><pre>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen# This example is valid in per-directory context only
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowenRewriteCond %{REQUEST_FILENAME} <strong>!-s</strong>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowenRewriteRule ^page\.<strong>html</strong>$ page.<strong>cgi</strong> [T=application/x-httpd-cgi,L]
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen</pre></div>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <p>Here a request for <code>page.html</code> leads to an
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen internal run of a corresponding <code>page.cgi</code> if
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <code>page.html</code> is missing or has filesize
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen null. The trick here is that <code>page.cgi</code> is a
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen CGI script which (additionally to its <code>STDOUT</code>)
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen writes its output to the file <code>page.html</code>.
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen Once it has completed, the server sends out
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <code>page.html</code>. When the webmaster wants to force
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen a refresh of the contents, he just removes
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen <code>page.html</code> (typically from <code>cron</code>).</p>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen </dd>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen </dl>
b0306ceedec510a7b4ebe3a1b70c366bf5f2727crbowen
1525d3506d73644ae695624f16b15cc73cc1c7acrbowen</div></div>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<div class="bottomlang">
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<p><span>Available Languages: </span><a href="/en/rewrite/avoid.html" title="English">&nbsp;en&nbsp;</a></p>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen</div><div id="footer">
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<p class="apache">Copyright 2009 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>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen<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>
b630661b71a5495a95831a05a6a2299fb1c7c771rbowen</body></html>