]> granicus.if.org Git - apache/blob - docs/manual/rewrite/remapping.html.en
Encourage people to use Redirect rather than mod_rewrite.
[apache] / docs / manual / rewrite / remapping.html.en
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
7       -->
8 <title>Redirecting and Remapping with mod_rewrite - 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="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
18 <div id="path">
19 <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>Redirecting and Remapping with mod_rewrite</h1>
20 <div class="toplang">
21 <p><span>Available Languages: </span><a href="../en/rewrite/remapping.html" title="English">&nbsp;en&nbsp;</a></p>
22 </div>
23
24
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 you can use <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> to redirect and remap
28 request. This includes many examples of common uses of mod_rewrite,
29 including detailed descriptions of how each works.</p>
30
31 <div class="warning">Note that many of these examples won't work unchanged in your
32 particular server configuration, so it's important that you understand
33 them, rather than merely cutting and pasting the examples into your
34 configuration.</div>
35
36 </div>
37 <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#old-to-new">From Old to New (internal)</a></li>
38 <li><img alt="" src="../images/down.gif" /> <a href="#old-to-new-extern">Rewriting From Old to New (external)</a></li>
39 <li><img alt="" src="../images/down.gif" /> <a href="#movehomedirs">Resource Moved to Another Server</a></li>
40 <li><img alt="" src="../images/down.gif" /> <a href="#static-to-dynamic">From Static to Dynamic</a></li>
41 <li><img alt="" src="../images/down.gif" /> <a href="#backward-compatibility">Backward Compatibility for file extension change</a></li>
42 <li><img alt="" src="../images/down.gif" /> <a href="#canonicalhost">Canonical Hostnames</a></li>
43 <li><img alt="" src="../images/down.gif" /> <a href="#multipledirs">Search for pages in more than one directory</a></li>
44 <li><img alt="" src="../images/down.gif" /> <a href="#archive-access-multiplexer">Redirecting to Geographically Distributed Servers</a></li>
45 <li><img alt="" src="../images/down.gif" /> <a href="#browser-dependent-content">Browser Dependent Content</a></li>
46 <li><img alt="" src="../images/down.gif" /> <a href="#canonicalurl">Canonical URLs</a></li>
47 <li><img alt="" src="../images/down.gif" /> <a href="#moveddocroot">Moved <code>DocumentRoot</code></a></li>
48 <li><img alt="" src="../images/down.gif" /> <a href="#fallback-resource">Fallback Resource</a></li>
49 </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><li><a href="access.html">Controlling access</a></li><li><a href="vhosts.html">Virtual hosts</a></li><li><a href="proxy.html">Proxying</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>
50 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
51 <div class="section">
52 <h2><a name="old-to-new" id="old-to-new">From Old to New (internal)</a></h2>
53
54   
55
56   <dl>
57     <dt>Description:</dt>
58
59     <dd>
60       <p>Assume we have recently renamed the page
61       <code>foo.html</code> to <code>bar.html</code> and now want
62       to provide the old URL for backward compatibility. However,
63       we want that users of the old URL even not recognize that
64       the pages was renamed - that is, we don't want the address to
65       change in their browser.</p>
66     </dd>
67
68     <dt>Solution:</dt>
69
70     <dd>
71       <p>We rewrite the old URL to the new one internally via the
72       following rule:</p>
73
74 <div class="example"><pre>
75 RewriteEngine  on
76 RewriteRule    ^<strong>/old</strong>\.html$  <strong>/new</strong>.html [PT]
77 </pre></div>
78     </dd>
79   </dl>
80
81 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
82 <div class="section">
83 <h2><a name="old-to-new-extern" id="old-to-new-extern">Rewriting From Old to New (external)</a></h2>
84
85   
86
87   <dl>
88     <dt>Description:</dt>
89
90     <dd>
91       <p>Assume again that we have recently renamed the page
92       <code>foo.html</code> to <code>bar.html</code> and now want
93       to provide the old URL for backward compatibility. But this
94       time we want that the users of the old URL get hinted to
95       the new one, i.e. their browsers Location field should
96       change, too.</p>
97     </dd>
98
99     <dt>Solution:</dt>
100
101     <dd>
102       <p>We force a HTTP redirect to the new URL which leads to a
103       change of the browsers and thus the users view:</p>
104
105 <div class="example"><pre>
106 RewriteEngine  on
107 RewriteRule    ^<strong>/foo</strong>\.html$  <strong>bar</strong>.html  [<strong>R</strong>]
108 </pre></div>
109 </dd>
110
111 <dt>Discussion</dt>
112
113     <dd>
114     <p>In this example, as contrasted to the <a href="#old-to-new-intern">internal</a> example above, we can simply
115     use the Redirect directive. mod_rewrite was used in that earlier
116     example in order to hide the redirect from the client:</p>
117
118     <div class="example"><p><code>
119     Redirect /foo.html /bar.html
120     </code></p></div>
121
122     </dd>
123   </dl>
124
125 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
126 <div class="section">
127 <h2><a name="movehomedirs" id="movehomedirs">Resource Moved to Another Server</a></h2>
128
129   
130
131   <dl>
132     <dt>Description:</dt>
133
134     <dd>
135       <p>If a resource has moved to another server, you may wish to have
136       URLs continue to work for a time on the old server while people
137       update their bookmarks.</p>
138     </dd>
139
140     <dt>Solution:</dt>
141
142     <dd>
143       <p>You can use <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> to redirect these URLs
144       to the new server, but you might also consider using the Redirect
145       or RedirectMatch directive.</p>
146
147 <div class="example"><h3>With mod_rewrite</h3><pre>
148 RewriteEngine on
149 RewriteRule   ^/docs/(.+)  http://new.example.com/docs/$1  [R,L]
150 </pre></div>
151
152 <div class="example"><h3>With RedirectMatch</h3><pre>
153 RedirectMatch ^/docs/(.*) http://new.example.com/docs/$1
154 </pre></div>
155
156 <div class="example"><h3>With Redirect</h3><pre>
157 Redirect /docs/ http://new.example.com/docs/
158 </pre></div>
159     </dd>
160   </dl>
161
162 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
163 <div class="section">
164 <h2><a name="static-to-dynamic" id="static-to-dynamic">From Static to Dynamic</a></h2>
165
166   
167
168   <dl>
169     <dt>Description:</dt>
170
171     <dd>
172       <p>How can we transform a static page
173       <code>foo.html</code> into a dynamic variant
174       <code>foo.cgi</code> in a seamless way, i.e. without notice
175       by the browser/user.</p>
176     </dd>
177
178     <dt>Solution:</dt>
179
180     <dd>
181       <p>We just rewrite the URL to the CGI-script and force the
182       handler to be <strong>cgi-script</strong> so that it is
183       executed as a CGI program.
184       This way a request to <code>/~quux/foo.html</code>
185       internally leads to the invocation of
186       <code>/~quux/foo.cgi</code>.</p>
187
188 <div class="example"><pre>
189 RewriteEngine  on
190 RewriteBase    /~quux/
191 RewriteRule    ^foo\.<strong>html</strong>$  foo.<strong>cgi</strong>  [H=<strong>cgi-script</strong>]
192 </pre></div>
193     </dd>
194   </dl>
195
196 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
197 <div class="section">
198 <h2><a name="backward-compatibility" id="backward-compatibility">Backward Compatibility for file extension change</a></h2>
199
200   
201
202   <dl>
203     <dt>Description:</dt>
204
205     <dd>
206       <p>How can we make URLs backward compatible (still
207       existing virtually) after migrating <code>document.YYYY</code>
208       to <code>document.XXXX</code>, e.g. after translating a
209       bunch of <code>.html</code> files to <code>.php</code>?</p>
210     </dd>
211
212     <dt>Solution:</dt>
213
214     <dd>
215       <p>We rewrite the name to its basename and test for
216       existence of the new extension. If it exists, we take
217       that name, else we rewrite the URL to its original state.</p>
218
219 <div class="example"><pre>
220 #   backward compatibility ruleset for
221 #   rewriting document.html to document.php
222 #   when and only when document.php exists
223 &lt;Directory /var/www/htdocs&gt;
224 RewriteEngine on
225 RewriteBase /var/www/htdocs
226
227 RewriteCond $1.php -f
228 RewriteCond $1.html !-f
229 RewriteRule ^(.*).html$ $1.php
230 &lt;/Directory&gt;
231 </pre></div>
232     </dd>
233
234     <dt>Discussion</dt>
235     <dd>
236     <p>This example uses an often-overlooked feature of mod_rewrite,
237     by taking advantage of the order of execution of the ruleset. In
238     particular, mod_rewrite evaluates the left-hand-side of the
239     RewriteRule before it evaluates the RewriteCond directives.
240     Consequently, $1 is already defined by the time the RewriteCond
241     directives are evaluated. This allows us to test for the existence
242     of the original (<code>document.html</code>) and target
243     (<code>document.php</code>) files using the same base filename.</p>
244
245     <p>This ruleset is designed to use in a per-directory context (In a
246     &lt;Directory&gt; block or in a .htaccess file), so that the
247     <code>-f</code> checks are looking at the correct directory path.
248     You may need to set a <code class="directive"><a href="../mod/mod_rewite.html#rewritebase">RewriteBase</a></code> directive to specify the
249     directory base that you're working in.</p>
250     </dd>
251   </dl>
252
253 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
254 <div class="section">
255 <h2><a name="canonicalhost" id="canonicalhost">Canonical Hostnames</a></h2>
256
257
258
259       <dl>
260         <dt>Description:</dt>
261
262         <dd>The goal of this rule is to force the use of a particular
263         hostname, in preference to other hostnames which may be used to
264         reach the same site. For example, if you wish to force the use
265         of <strong>www.example.com</strong> instead of
266         <strong>example.com</strong>, you might use a variant of the
267         following recipe.</dd>
268
269         <dt>Solution:</dt>
270
271         <dd>
272
273 <p>The very best way to solve this doesn't involve mod_rewrite at all,
274 but rather uses the <code class="directive"><a href="../mod/alias.html#redirect">Redirect</a></code>
275 directive places in a virtual host for the non-canonical
276 hostname(s).</p>
277
278 <div class="example"><pre>
279 &lt;VirtualHost *:80&gt;
280   ServerName undesired.example.com
281   ServerAlias example.com notthis.example.com
282
283   Redirect / http://www.example.com/
284 &lt;/VirtualHost&gt;
285 </pre></div>
286
287 <p>However, there are situations where you'll need to use mod_rewrite -
288 primarily when you don't have access to the main server configuration
289 file, or if you wish to do this dynamically for a larger number of
290 hostnames. For these situations, you might use one of the recipes
291 below.</p>
292
293 <p>For sites running on a port other than 80:</p>
294 <div class="example"><pre>
295 RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
296 RewriteCond %{HTTP_HOST}   !^$
297 RewriteCond %{SERVER_PORT} !^80$
298 RewriteRule ^/?(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R,NE]
299 </pre></div>
300
301 <p>And for a site running on port 80</p>
302 <div class="example"><pre>
303 RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
304 RewriteCond %{HTTP_HOST}   !^$
305 RewriteRule ^/?(.*)         http://www.example.com/$1 [L,R,NE]
306 </pre></div>
307
308         <p>
309         If you wanted to do this generically for all domain names - that
310         is, if you want to redirect <strong>example.com</strong> to
311         <strong>www.example.com</strong> for all possible values of
312         <strong>example.com</strong>, you could use the following
313         recipe:</p>
314
315 <div class="example"><pre>
316 RewriteCond %{HTTP_HOST} !^www\. [NC]
317 RewriteCond %{HTTP_HOST} !^$
318 RewriteRule ^/?(.*) http://www.%{HTTP_HOST}/$1 [L,R,NE]
319 </pre></div>
320
321     <p>These rulesets will work either in your main server configuration
322     file, or in a <code>.htaccess</code> file placed in the <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code> of the server.</p>
323         </dd>
324       </dl>
325
326 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
327 <div class="section">
328 <h2><a name="multipledirs" id="multipledirs">Search for pages in more than one directory</a></h2>
329
330   
331
332   <dl>
333     <dt>Description:</dt>
334
335     <dd>
336       <p>A particular resource might exist in one of several places, and
337       we want to look in those places for the resource when it is
338       requested. Perhaps we've recently rearranged our directory
339       structure, dividing content into several locations.</p>
340     </dd>
341
342     <dt>Solution:</dt>
343
344     <dd>
345       <p>The following ruleset searches in two directories to find the
346       resource, and, if not finding it in either place, will attempt to
347       just serve it out of the location requested.</p>
348
349 <div class="example"><pre>
350 RewriteEngine on
351
352 #   first try to find it in dir1/...
353 #   ...and if found stop and be happy:
354 RewriteCond         %{DOCUMENT_ROOT}/<strong>dir1</strong>/%{REQUEST_URI}  -f
355 RewriteRule  ^(.+)  %{DOCUMENT_ROOT}/<strong>dir1</strong>/$1  [L]
356
357 #   second try to find it in dir2/...
358 #   ...and if found stop and be happy:
359 RewriteCond         %{DOCUMENT_ROOT}/<strong>dir2</strong>/%{REQUEST_URI}  -f
360 RewriteRule  ^(.+)  %{DOCUMENT_ROOT}/<strong>dir2</strong>/$1  [L]
361
362 #   else go on for other Alias or ScriptAlias directives,
363 #   etc.
364 RewriteRule   ^  -  [PT]
365 </pre></div>
366     </dd>
367   </dl>
368
369 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
370 <div class="section">
371 <h2><a name="archive-access-multiplexer" id="archive-access-multiplexer">Redirecting to Geographically Distributed Servers</a></h2>
372
373   
374
375   <dl>
376     <dt>Description:</dt>
377
378     <dd>
379     <p>We have numerous mirrors of our website, and want to redirect
380     people to the one that is located in the country where they are
381     located.</p>
382     </dd>
383
384     <dt>Solution:</dt>
385
386     <dd>
387     <p>Looking at the hostname of the requesting client, we determine
388     which country they are coming from. If we can't do a lookup on their
389     IP address, we fall back to a default server.</p>
390     <p>We'll use a <code class="directive"><a href="../mod/mod_rewrite.html#rewritemap">RewriteMap</a></code>
391     directive to build a list of servers that we wish to use.</p>
392
393 <div class="example"><pre>
394 HostnameLookups on
395 RewriteEngine on
396 RewriteMap    multiplex         txt:/path/to/map.mirrors
397 RewriteCond  %{REMOTE_HOST}     ([a-z]+)$ [NC]
398 RewriteRule   ^/(.*)$  ${multiplex:<strong>%1</strong>|http://www.example.com/}$1  [R,L]
399 </pre></div>
400
401 <div class="example"><pre>
402 ##  map.mirrors -- Multiplexing Map
403
404 de        http://www.example.de/
405 uk        http://www.example.uk/
406 com       http://www.example.com/
407 ##EOF##
408 </pre></div>
409     </dd>
410
411     <dt>Discussion</dt>
412     <dd>
413     <div class="warning">This ruleset relies on 
414     <code class="directive"><a href="../mod/core.html#hostnamelookups">HostNameLookups</a></code> 
415     being set <code>on</code>, which can be
416     a significant performance hit.</div>
417
418     <p>The <code class="directive"><a href="../mod/mod_rewrite.html#rewritecond">RewriteCond</a></code>
419     directive captures the last portion of the hostname of the
420     requesting client - the country code - and the following RewriteRule
421     uses that value to look up the appropriate mirror host in the map
422     file.</p>
423     </dd>
424   </dl>
425
426 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
427 <div class="section">
428 <h2><a name="browser-dependent-content" id="browser-dependent-content">Browser Dependent Content</a></h2>
429
430   
431
432   <dl>
433     <dt>Description:</dt>
434
435     <dd>
436       <p>We wish to provide different content based on the browser, or
437       user-agent, which is requesting the content.</p>
438     </dd>
439
440     <dt>Solution:</dt>
441
442     <dd>
443       <p>We have to decide, based on the HTTP header "User-Agent",
444       which content to serve. The following config
445       does the following: If the HTTP header "User-Agent"
446       contains "Mozilla/3", the page <code>foo.html</code>
447       is rewritten to <code>foo.NS.html</code> and the
448       rewriting stops. If the browser is "Lynx" or "Mozilla" of
449       version 1 or 2, the URL becomes <code>foo.20.html</code>.
450       All other browsers receive page <code>foo.32.html</code>.
451       This is done with the following ruleset:</p>
452
453 <div class="example"><pre>
454 RewriteCond %{HTTP_USER_AGENT}  ^<strong>Mozilla/3</strong>.*
455 RewriteRule ^foo\.html$         foo.<strong>NS</strong>.html          [<strong>L</strong>]
456
457 RewriteCond %{HTTP_USER_AGENT}  ^<strong>Lynx/</strong>.*         [OR]
458 RewriteCond %{HTTP_USER_AGENT}  ^<strong>Mozilla/[12]</strong>.*
459 RewriteRule ^foo\.html$         foo.<strong>20</strong>.html          [<strong>L</strong>]
460
461 RewriteRule ^foo\.html$         foo.<strong>32</strong>.html          [<strong>L</strong>]
462 </pre></div>
463     </dd>
464   </dl>
465
466 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
467 <div class="section">
468 <h2><a name="canonicalurl" id="canonicalurl">Canonical URLs</a></h2>
469
470
471
472 <dl>
473  <dt>Description:</dt>
474
475    <dd>
476      <p>On some webservers there is more than one URL for a
477      resource. Usually there are canonical URLs (which are be
478      actually used and distributed) and those which are just
479      shortcuts, internal ones, and so on. Independent of which URL the
480      user supplied with the request, they should finally see the
481      canonical one in their browser address bar.</p>
482    </dd>
483
484    <dt>Solution:</dt>
485
486      <dd>
487        <p>We do an external HTTP redirect for all non-canonical
488        URLs to fix them in the location view of the Browser and
489        for all subsequent requests. In the example ruleset below
490        we replace <code>/puppies</code> and <code>/canines</code>
491        by the canonical <code>/dogs</code>.</p>
492
493 <div class="example"><pre>
494 RewriteRule   ^/(puppies|canines)/(.*)    /dogs/$2  [R]
495 </pre></div>
496         </dd>
497
498      <dt>Discussion:</dt>
499      <dd>
500      This should really be accomplished with Redirect or RedirectMatch
501      directives:
502
503      <div class="example"><pre>
504      RedirectMatch ^/(puppies|canines)/(.*) /dogs/$2
505      </pre></div>
506      </dd>
507       </dl>
508
509 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
510 <div class="section">
511 <h2><a name="moveddocroot" id="moveddocroot">Moved <code>DocumentRoot</code></a></h2>
512
513   
514
515   <dl>
516     <dt>Description:</dt>
517
518     <dd>
519 <p>Usually the <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>
520 of the webserver directly relates to the URL "<code>/</code>".
521 But often this data is not really of top-level priority. For example,
522 you may wish for visitors, on first entering a site, to go to a
523 particular subdirectory <code>/about/</code>. This may be accomplished
524 using the following ruleset:</p>
525 </dd>
526
527     <dt>Solution:</dt>
528
529     <dd>
530       <p>We redirect the URL <code>/</code> to
531       <code>/about/</code>:
532       </p>
533      
534 <div class="example"><pre>
535 RewriteEngine on
536 RewriteRule   <strong>^/$</strong>  /about/  [<strong>R</strong>]
537 </pre></div>
538
539 <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>
540
541 <div class="example"><p><code>
542 RedirectMatch ^/$ http://example.com/about/
543 </code></p></div>
544
545 <p>Note also that the example rewrites only the root URL. That is, it
546 rewrites a request for <code>http://example.com/</code>, but not a
547 request for <code>http://example.com/page.html</code>. If you have in 
548 fact changed your document root - that is, if <strong>all</strong> of 
549 your content is in fact in that subdirectory, it is greatly preferable 
550 to simply change your <code class="directive"><a href="../mod/core.html#documentroot">DocumentRoot</a></code>
551 directive, or move all of the content up one directory,
552 rather than rewriting URLs.</p>
553 </dd>
554 </dl>
555
556 </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
557 <div class="section">
558 <h2><a name="fallback-resource" id="fallback-resource">Fallback Resource</a></h2>
559
560
561 <dl>
562 <dt>Description:</dt>
563 <dd>You want a single resource (say, a certain file, like index.php) to
564 handle all requests that come to a particular directory, except those
565 that should go to an existing resource such as an image, or a css file.</dd>
566
567 <dt>Solution:</dt>
568 <dd>
569 <p>As of version 2.4, you should use the <code class="directive"><a href="../mod/mod_dir.html#fallbackresource">FallbackResource</a></code> directive for this:</p>
570
571 <div class="example"><pre>
572 &lt;Directory /var/www/my_blog&gt;
573   FallbackResource index.php
574 &lt;/Directory&gt;
575 </pre></div>
576
577 <p>However, in earlier versions of Apache, or if your needs are more
578 complicated than this, you can use a variation of the following rewrite
579 set to accomplish the same thing:</p>
580
581 <div class="example"><pre>
582 &lt;Directory /var/www/my_blog&gt;
583   RewriteBase /my_blog
584
585   RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-f
586   RewriteCond /var/www/my_blog/%{REQUEST_FILENAME} !-d
587   RewriteRule ^ index.php [PT]
588 &lt;/Directory&gt;
589 </pre></div>
590
591 <p>If, on the other hand, you wish to pass the requested URI as a query
592 string argument to index.php, you can replace that RewriteRule with:</p>
593
594 <div class="example"><pre>
595   RewriteRule (.*) index.php?$1 [PT,QSA]
596 </pre></div>
597
598 <p>Note that these rulesets can be uses in a <code>.htaccess</code>
599 file, as well as in a &lt;Directory&gt; block.</p>
600
601 </dd>
602
603 </dl>
604
605 </div></div>
606 <div class="bottomlang">
607 <p><span>Available Languages: </span><a href="../en/rewrite/remapping.html" title="English">&nbsp;en&nbsp;</a></p>
608 </div><div id="footer">
609 <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>
610 <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>
611 </body></html>