]> granicus.if.org Git - apache/blobdiff - docs/manual/rewrite/flags.xml
Rebuild.
[apache] / docs / manual / rewrite / flags.xml
index b12cad3d3b37b648cdb92d63913ac407a0bc0b3f..3c7aceef3e1e7c31a20e7226d25a34456cd02291 100644 (file)
@@ -70,7 +70,7 @@ of how you might use them.</p>
 <p>The [B] flag instructs <directive
 module="mod_rewrite">RewriteRule</directive> to escape non-alphanumeric
 characters before applying the transformation.</p>
-<p>In 2.4.10 and later, you can limit the escaping to specific characters
+<p>In 2.4.26 and later, you can limit the escaping to specific characters
 in backreferences by listing them: <code>[B=#?;]</code>. Note: The space
 character can be used in the list of characters to escape, but it cannot be
 the last character in the list.</p>
@@ -81,7 +81,7 @@ Using the B flag, non-alphanumeric characters in backreferences
 will be escaped. For example, consider the rule:</p>
 
 <highlight language="config">
-RewriteRule ^search/(.*)$ /search.php?term=$1
+RewriteRule "^search/(.*)$" "/search.php?term=$1"
 </highlight>
 
 <p>Given a search term of 'x &amp; y/z', a browser will encode it as
@@ -94,6 +94,10 @@ isn't a valid URL, and so would be encoded as
 before being passed on to the output URL, resulting in a correct mapping to
 <code>/search.php?term=x%20%26%20y%2Fz</code>.</p>
 
+<highlight language="config">
+RewriteRule "^search/(.*)$" "/search.php?term=$1" [B,PT]
+</highlight>
+
 <p>Note that you may also need to set <directive
 module="core">AllowEncodedSlashes</directive> to <code>On</code> to get this
 particular example to work, as httpd does not allow encoded slashes in URLs, and
@@ -112,6 +116,9 @@ strings in the encoded form.</p>
 module="mod_rewrite">RewriteRule</directive> to escape the space character
 in a backreference to %20 rather than '+'. Useful when the backreference
 will be used in the path component rather than the query string.</p>
+
+<p>This flag is available in version 2.4.26 and later.</p>
+
 </section>
 
 <section id="flag_c"><title>C|chain</title>
@@ -137,6 +144,15 @@ follows:</p>
 [CO=NAME:VALUE:DOMAIN:lifetime:path:secure:httponly]
 </example>
 
+<p>If a literal ':' character is needed in any of the cookie fields, an 
+alternate syntax is available.  To opt-in to the alternate syntax, the cookie 
+"Name" should be preceded with a ';' character, and field separators should be
+specified as ';'.</p>
+
+<example>
+[CO=;NAME;VALUE:MOREVALUE;DOMAIN;lifetime;path;secure;httponly]
+</example>
+
 <p>You must declare a name, a value, and a domain for the cookie to be set.</p>
 
 <dl>
@@ -180,7 +196,7 @@ browsers that support this feature.</dd>
 
 <highlight language="config">
 RewriteEngine On
-RewriteRule ^/index\.html - [CO=frontdoor:yes:.example.com:1440:/]
+RewriteRule   "^/index\.html"   "-" [CO=frontdoor:yes:.example.com:1440:/]
 </highlight>
 
 <p>In the example give, the rule doesn't rewrite the request.
@@ -231,10 +247,10 @@ variables work.</p>
 
 <p>The full syntax for this flag is:</p>
 
-<example>
+<highlight language="config">
 [E=VAR:VAL]
 [E=!VAR]
-</example>
+</highlight>
 
 <p><code>VAL</code> may contain backreferences (<code>$N</code> or
 <code>%N</code>) which are expanded.</p>
@@ -267,8 +283,8 @@ environment variable is used to exclude those requests from the access
 log.</p>
 
 <highlight language="config">
-RewriteRule \.(png|gif|jpg)$ - [E=image:1]
-CustomLog logs/access_log combined env=!image
+RewriteRule "\.(png|gif|jpg)$"   "-" [E=image:1]
+CustomLog   "logs/access_log"    combined env=!image
 </highlight>
 
 <p>Note that this same effect can be obtained using <directive
@@ -295,7 +311,7 @@ allows more flexibility in assigning a Forbidden status.</p>
 downloaded from your server.</p>
 
 <highlight language="config">
-RewriteRule \.exe - [F]
+RewriteRule "\.exe"   "-" [F]
 </highlight>
 
 <p>This example uses the "-" syntax for the rewrite target, which means
@@ -316,7 +332,7 @@ longer available.</p>
 rewrite target when using the [G] flag:</p>
 
 <highlight language="config">
-RewriteRule oldproduct - [G,NC]
+RewriteRule "oldproduct"   "-" [G,NC]
 </highlight>
 
 <p>When using [G], an [L] is implied - that is, the response is returned
@@ -330,7 +346,7 @@ handler. For example, one might use this to force all files without a
 file extension to be parsed by the php handler:</p>
 
 <highlight language="config">
-RewriteRule !\. - [H=application/x-httpd-php]
+RewriteRule "!\."  "-" [H=application/x-httpd-php]
 </highlight>
 
 <p>
@@ -344,7 +360,7 @@ For example, the following snippet used in per-server context allows
 if they are requested with the <code>.phps</code> extension:</p>
 
 <highlight language="config">
-RewriteRule ^(/source/.+\.php)s$ $1 [H=application/x-httpd-php-source]
+RewriteRule "^(/source/.+\.php)s$" "$1" [H=application/x-httpd-php-source]
 </highlight>
 
 <p>The regular expression above - <code>^(/source/.+\.php)s$</code> - will
@@ -397,9 +413,9 @@ is already for <code>index.php</code>, the <directive
 module="mod_rewrite">RewriteRule</directive> will be skipped.</p>
 
 <highlight language="config">
-RewriteBase /
-RewriteCond %{REQUEST_URI} !=/index.php
-RewriteRule ^(.*) /index.php?req=$1 [L,PT]
+RewriteBase "/"
+RewriteCond "%{REQUEST_URI}" !=/index.php
+RewriteRule "^(.*)"          "/index.php?req=$1" [L,PT]
 </highlight>
 </section>
 
@@ -416,7 +432,7 @@ will replace A with B everywhere in a request, and will continue doing
 so until there are no more As to be replaced.
 </p>
 <highlight language="config">
-RewriteRule (.*)A(.*) $1B$2 [N]
+RewriteRule "(.*)A(.*)" "$1B$2" [N]
 </highlight>
 <p>You can think of this as a <code>while</code> loop: While this
 pattern still matches (i.e., while the URI still contains an
@@ -428,9 +444,9 @@ protect against unintended looping.  An alternative maximum number of
 iterations can be specified by adding to the N flag.  </p>
 <highlight language="config">
 # Be willing to replace 1 character in each pass of the loop
-RewriteRule (.+)[&gt;&lt;;]$ $1 [N=32000]
+RewriteRule "(.+)[&gt;&lt;;]$" "$1" [N=32000]
 # ... or, give up if after 10 loops
-RewriteRule (.+)[&gt;&lt;;]$ $1 [N=10]
+RewriteRule "(.+)[&gt;&lt;;]$" "$1" [N=10]
 </highlight>
 
 </section>
@@ -447,7 +463,7 @@ to your dedicated image server. The match is case-insensitive, so that
 example.</p>
 
 <highlight language="config">
-RewriteRule (.*\.(jpg|gif|png))$ http://images.example.com$1 [P,NC]
+RewriteRule "(.*\.(jpg|gif|png))$" "http://images.example.com$1" [P,NC]
 </highlight>
 </section>
 
@@ -458,7 +474,7 @@ equivalent. Using the [NE] flag prevents that from happening.
 </p>
 
 <highlight language="config">
-RewriteRule ^/anchor/(.+) /bigpage.html#$1 [NE,R]
+RewriteRule "^/anchor/(.+)" "/bigpage.html#$1" [NE,R]
 </highlight>
 
 <p>
@@ -501,7 +517,7 @@ example, if you wanted all image requests to be handled by a back-end
 image server, you might do something like the following:</p>
 
 <highlight language="config">
-RewriteRule /(.*)\.(jpg|gif|png)$ http://images.example.com/$1.$2 [P]
+RewriteRule "/(.*)\.(jpg|gif|png)$" "http://images.example.com/$1.$2" [P]
 </highlight>
 
 <p>Use of the [P] flag implies [L] - that is, the request is immediately
@@ -566,7 +582,7 @@ use the [PT] flag to ensure that the
 
 <highlight language="config">
 Alias "/icons" "/usr/local/apache/icons"
-RewriteRule /pics/(.+)\.jpg$ /icons/$1.gif [PT]
+RewriteRule "/pics/(.+)\.jpg$" "/icons/$1.gif" [PT]
 </highlight>
 
 <p>
@@ -597,7 +613,7 @@ Using the [QSA] flag causes the query strings to be combined.
 <p>Consider the following rule:</p>
 
 <highlight language="config">
-RewriteRule /pages/(.+) /page.php?page=$1 [QSA]
+RewriteRule "/pages/(.+)" "/page.php?page=$1" [QSA]
 </highlight>
 
 <p>With the [QSA] flag, a request for <code>/pages/123?one=two</code> will be
@@ -632,6 +648,23 @@ URI.
 
 </section>
 
+<section id="flag_qsl"><title>QSL|qslast</title>
+<p>
+By default, the first (left-most) question mark in the substitution
+delimits the path from the query string.  Using the [QSL] flag instructs
+<directive module="mod_rewrite">RewriteRule</directive> to instead split
+the two components using the last (right-most) question mark.  </p>
+
+<p>
+This is useful when mapping to files that have literal question marks in 
+their filename.  If no query string is used in the substitution, 
+a question mark can be appended to it in combination with this flag.  </p>
+
+<p> This flag is available in version 2.4.19 and later.</p>
+
+</section>
+
+
 <section id="flag_r"><title>R|redirect</title>
 <p>
 Use of the [R] flag causes a HTTP redirect to be issued to the browser.
@@ -677,13 +710,13 @@ actual file.</p>
 
 <highlight language="config">
 # Is the request for a non-existent file?
-RewriteCond %{REQUEST_FILENAME} !-f
-RewriteCond %{REQUEST_FILENAME} !-d
+RewriteCond "%{REQUEST_FILENAME}" !-f
+RewriteCond "%{REQUEST_FILENAME}" !-d
 # If so, skip these two RewriteRules
-RewriteRule .? - [S=2]
+RewriteRule ".?"                  "-" [S=2]
 
-RewriteRule (.*\.gif) images.php?$1
-RewriteRule (.*\.html) docs.php?$1
+RewriteRule "(.*\.gif)"           "images.php?$1"
+RewriteRule "(.*\.html)"          "docs.php?$1"
 </highlight>
 
 <p>This technique is useful because a <directive
@@ -697,18 +730,18 @@ the then-clause becomes <code>skip=N</code>, where N is the
 number of rules in the else-clause:</p>
 <highlight language="config">
 # Does the file exist?
-RewriteCond %{REQUEST_FILENAME} !-f
-RewriteCond %{REQUEST_FILENAME} !-d
+RewriteCond "%{REQUEST_FILENAME}" !-f
+RewriteCond "%{REQUEST_FILENAME}" !-d
 # Create an if-then-else construct by skipping 3 lines if we meant to go to the &quot;else&quot; stanza.
-RewriteRule .? - [S=3]
+RewriteRule ".?"                  "-" [S=3]
 
 # IF the file exists, then:
-    RewriteRule (.*\.gif) images.php?$1
-    RewriteRule (.*\.html) docs.php?$1
+    RewriteRule "(.*\.gif)"  "images.php?$1"
+    RewriteRule "(.*\.html)" "docs.php?$1"
     # Skip past the &quot;else&quot; stanza.
-    RewriteRule .? - [S=1]
+    RewriteRule ".?"         "-" [S=1]
 # ELSE...
-    RewriteRule (.*) 404.php?file=$1
+    RewriteRule "(.*)"       "404.php?file=$1"
 # END
 </highlight>
 
@@ -729,7 +762,7 @@ source code as plain text, if requested in a particular way:</p>
 
 <highlight language="config">
 # Serve .pl files as plain text
-RewriteRule \.pl$ - [T=text/plain]
+RewriteRule "\.pl$"  "-" [T=text/plain]
 </highlight>
 
 <p>Or, perhaps, if you have a camera that produces jpeg images without
@@ -738,7 +771,7 @@ correct MIME type by virtue of their file names:</p>
 
 <highlight language="config">
 # Files with 'IMG' in the name are jpg images.
-RewriteRule IMG - [T=image/jpg]
+RewriteRule "IMG"  "-" [T=image/jpg]
 </highlight>
 
 <p>Please note that this is a trivial example, and could be better done