Dear Wiki user, You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change notification.
The following page has been changed by VinkoVrsalovic: http://wiki.apache.org/httpd/Recipes/QueryString The comment on the change is: Consistency var=val plus I really think showing [^/]+ is important. ------------------------------------------------------------------------------ === Access control by Query String === - Deny access to {{{http://example.com/page?query}}} if {{{query}}} contains the string {{{foo}}}. + Deny access to {{{http://example.com/page?var=val}}} if {{{var=val}}} contains the string {{{foo}}}. {{{ # using mod_rewrite @@ -30, +30 @@ === Adding to the Query String === - Keep the existing query string using the Query String Append flag, but add {{{var=value}}} to the end. + Keep the existing query string using the Query String Append flag, but add {{{var=val}}} to the end. {{{ - RewriteRule (.*) $1?var=value [QSA] + RewriteRule (.*) $1?var=val [QSA] }}} === Rewriting For Certain Query Strings === - Rewrite URLs like {{{http://example.com/page1?stuff}}} to {{{http://example.com/page2?stuff}}} (but don't rewrite if {{{stuff}}} isn't present). + Rewrite URLs like {{{http://example.com/page1?var=val}}} to {{{http://example.com/page2?var=val}}} but don't rewrite if {{{val}}} isn't present. {{{ - RewriteCond %{QUERY_STRING} ^stuff$ + RewriteCond %{QUERY_STRING} ^val$ Rewrite ^/page1 /page2 }}} + Note that you don't need to use the Query String Append flag if you won't modify the query string in the {{{RewriteRule}}}; it is left as-is in the URL by default. + === Modifying the Query String === - Change any single instance of {{{foo}}} in the query string to {{{bar}}} when accessing {{{/path}}}. Note that {{{%1}}} and {{{%2}}} are back-references to the matched part of the regular expression in the previous {{{RewriteCond}}}. + Change any single instance of {{{val}}} in the query string to {{{other_val}}} when accessing {{{/path}}}. Note that {{{%1}}} and {{{%2}}} are back-references to the matched part of the regular expression in the previous {{{RewriteCond}}}. {{{ - RewriteCond %{QUERY_STRING} ^(.*)foo(.*)$ + RewriteCond %{QUERY_STRING} ^(.*)val(.*)$ - RewriteRule /path /path?%1bar%2 + RewriteRule /path /path?%1other_val%2 }}} === Making the Query String Part of the Path === @@ -65, +67 @@ === Making the Path Part of the Query String === - Essentially the reverse of the above recipe. + Essentially the reverse of the above recipe. But this example, on the other hand, will work for any valid three level URL. {{{http://example.com/path/var/val}}} will be transformed into {{{http://example.com/path?var=val}}}. {{{ - RewriteRule ^/path/(\w+)/(\w+) /path?$1=$2 + RewriteRule ^/path/([^/]+)/([^/]+) /path?$1=$2 }}}
