« Online Tool compares Packer, JSMin, Dojo, and YUI CompressorCOMPUTER SECURITY TOOLBOX »
Mod_Rewrite Variables Cheatsheet
We’ve figured out what mod_rewrite variables look like so we can create rewriterules and condition patterns based on the actual value. This cheatsheet is where we’ll lay them all out for quick reference. This cheatsheet changed my life.
20020903:12
Digest
max-age=0
keep-alive
(null)
(null)
/home/webroot/askapache.com
www.askapache.com
off
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
__qca=1176541205adf28-5553185; ASKAPACHEID=fdadfa4f33e62a878468; __utmc=1df3893
www.askapache.com
http://www.askapache.com/pro/mod_rewrite/catch.php?k=i
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9) Firefox/3.0.1
false
300
/bin:/usr/bin:/sbin:/usr/sbin
k=i
22.162.134.211
22.162.134.211
4220
askapache
/home/webroot/askapache.com/pro/mod_rewrite/index.php
GET
HTTP/1.1
/pro/mod_rewrite/index.php
/home/webroot/askapache.com/pro/mod_rewrite/index.php
daemong
http://www.askapache.com/pro/mod_rewrite/index.php
/pro/mod_rewrite/index.php
askapache
208.113.134.190
webmaster@askapache.com
www.askapache.com
80
HTTP/1.1
Apache/2.0.61 (Unix) PHP/5.5 OpenSSL/0.9.7e
GET /pro/mod_rewrite/index.php?k=i HTTP/1.1
20080915152142
15
15
21
09
42
1
2008
qOr5tEBvcm8AAE-VoiUAAAAQ
This article is meant to prepare us for the advanced mod_rewrite examples that are soon to be published. The upcoming article is going to be examples using mod_rewrite to achieve some crazy stuff… Here the focus is on identifying mod_rewrite variables and defining the limits of the module by checking the mod_rewrite source code.
For a broader mod_rewrite cheat sheet, check this printable cheat sheet.
RewriteEngine on|off
On or Off to enable or disable (default) the whole rewriting engine
RewriteOptions Options
List of option strings to set
RewriteBase URL-path
the base URL of the per-directory context
RewriteCond TestString CondPattern
an input string and a to be applied regexp-pattern
RewriteRule Pattern Substitution [flags]
an URL-applied regexp-pattern and a substitution URL
RewriteMap MapName MapType:MapSource
a mapname and a filename
RewriteLock file-path
the filename of a lockfile used for inter-process synchronization
RewriteLog file-path
the filename of the rewriting logfile
RewriteLogLevel Level
the level of the rewriting logfile verbosity (0=none, 1=std, .., 9=max)
'env|E=VAR:VAL' (set environment variable)
RewriteRule (root|cmd)\.exe – [E=worm:nimda]
'forbidden|F' (force URL to be forbidden)
'gone|G' (force URL to be gone)
'handler|H=Content-handler' (force Content handler)
'last|L' (last rule)
'next|N' (next round)
'nocase|NC' (no case)
'noescape|NE' (no URI escaping of output)
'nosubreq|NS' (not for internal sub-requests)
'proxy|P' (force proxy)
'passthrough|PT' (pass through to next handler)
'qsappend|QSA' (query string append)
'redirect|R [=code]' (force redirect)
'skip|S=num' (skip next rule(s))
This flag forces the rewriting engine to skip the next num rules in sequence, if the current rule matches. Use this to make pseudo if-then-else constructs: The last rule of the then-clause becomes skip=N, where N is the number of rules in the else-clause. (This is not the same as the ‘chain|C’ flag!)
'type|T=MIME-type' (force MIME type)
Force the MIME-type of the target file to be MIME-type. This can be used to set up the content-type based on some conditions. For example, the following snippet allows .php files to be displayed by mod_php if they are called with the .phps extension:
%04d%02d%02d%02d%02d%02dflag ? "on" : "off" (main ? "true" : "false"); path_info; ap_auth_type; lookup_header("Host", ctx); ap_get_server_name(r); connection->remote_ip; connection->local_ip; lookup_header("Accept", ctx); the_request; "%d:%d",MODULE_MAGIC_NUMBER_MAJOR,MODULE_MAGIC_NUMBER_MINOR); lookup_header("Cookie", ctx); ap_get_server_port(r); r->connection->remote_addr->port user; ""; uri; ""; ap_get_remote_logname(r); lookup_header("Referer", ctx); args; server->server_admin; ap_document_root(r);lookup_header("Forwarded", ctx);method;lookup_header("User-Agent", ctx); same as request_filename same as script_filename protocolap_get_server_banner();lookup_header("Proxy-Connection", ctx);Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: %sRewriteCond: bad argument line RewriteCond: NoCase option for non-regex pattern %s is not supported and will be ignored.RewriteCond: cannot compile regular expression RewriteRule: invalid HTTP response code %s for flag RRewriteRule: unknown flag RewriteRule: cannot compile regular expression RewriteOptions: MaxRedirects option has been removed in favor of the global LimitInternalRecursion directive and will be ignored.RewriteOptions: unknown option RewriteMap: bad path to txt map: RewriteMap: bad path to rnd map: RewriteMap: bad map:RewriteMap: bad path to dbm map: RewriteMap: dbm type RewriteMap: bad path to prg map: RewriteMap: internal map not found:RewriteMap: bad path to txt map: RewriteMap: file for map not found:Invalid RewriteLock pathRewriteBase: only valid in per-directory config filesRewriteBase: empty URL not allowedRewriteBase: argument is not a valid URLRewriteCond: bad flag delimitersRewriteCond: unknown flagRewriteLog and RewriteLogLevel are not supported by this build of mod_rewrite because it was compiled using the -DREWRITELOG_DISABLED compiler option. You have to recompile mod_rewrite WITHOUT this option in order to use the rewrite log.mod_rewrite: Invalid RewriteLog path %smod_rewrite: could not open reliable pipe to RewriteLog filter %smod_rewrite: Invalid RewriteLog path %smod_rewrite: could not open RewriteLog file %smod_rewrite: Running external rewrite maps without defining a RewriteLock is DANGEROUS!mod_rewrite: could not start RewriteMap program %smod_rewrite: cant access text RewriteMap file %smod_rewrite: cant access DBM RewriteMap file %smod_rewrite: Parent could not create RewriteLock file %smod_rewrite: Parent could not set permissions on RewriteLock check User and Group directivesmod_rewrite: could not create rewrite_log_lockmod_rewrite: Could not set permissions on rewrite_log_lock check User and Group directivesmod_rewrite: could not init rewrite_mapr_lock_acquire in childmod_rewrite: could not init rewrite log lock in childmod_rewrite: could not init map cache in childsplit uri=%s -> uri=%s, args=%sreduce %s -> %sstrip matching prefix: %s -> %sadd subst prefix: %s -> %scant open RewriteMap file, see error logcache lookup FAILED, forcing new map lookupmap lookup FAILED: map=%s[txt] key=%smap lookup OK: map=%s[txt] key=%s -> val=%scache lookup OK: map=%s[txt] key=%s -> val=%srandomly chosen the subvalue `%scant open DBM RewriteMap file, see error logcache lookup FAILED, forcing new map lookupmap lookup FAILED: map=%s[dbm] key=%smap lookup OK: map=%s[dbm] key=%s -> val=%scache lookup OK: map=%s[dbm] key=%s -> val=%smap lookup FAILED: map=%s key=%smap lookup OK: map=%s key=%s -> val=%smap lookup FAILED: map=%s key=%smap lookup OK: map=%s key=%s -> val=%slookahead: path=%s var=%s -> val=%slookahead: path=%s var=%s -> val=%sRESULT=%sescaping backreference %s to %ssetting env variable %s to %ssetting cookie %s, cookieskipping already set cookie %sRewriteCond URI (-U) check: path=%s -> status=%dRewriteCond file (-F) check: path=%s -> file=%s status=%dRewriteCond: input=%s pattern=%s%s%s%s => %sremember %s to have MIME-type %sremember %s to have Content-handler %sadd path info postfix: %s -> %s%sstrip per-dir prefix: %s -> %sapplying pattern %s to uri %srewrite %s -> %s, ctx->uriforcing responsecode %d for %sadd per-dir prefix: %s -> %s%sforcing proxy-throughput with %sexplicitly forcing redirect with %simplicitly forcing redirect (rc=%d) with %sforcing %s to get passed through to next API URI-to-filename handlerinit rewrite engine with requested uri %sgo-ahead with proxy request %s [OK]dconf->directory,trying to replace prefix %s with %sescaping %s for redirectredirect to %s [REDIRECT/%d]initial URL equal rewritten URL: %s [IGNORING REWRITE]dconf->directory, trying to replace prefix %s with %sstrip document_root prefix: %s -> %sinternal redirect with %s [INTERNAL REDIRECT]pass through %sforce filename %s to have MIME-type %sforce filename %s to have the Content-handler %s,init rewrite engine with requested uri %sinit rewrite engine with passed filename %s. Original uri = %suri already rewritten. Status %s, Uri %s, %sattempt to make remote request from mod_rewrite without proxy enabled: %sgo-ahead with proxy request %s [OK]escaping %s for redirectredirect to %s [REDIRECT/%d]local path result: %sprefixing with document_root of %s FAILEDprefixed with document_root to %sgo-ahead with %s [OK]pass through %sThis module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly.
It supports an unlimited number of additional rule conditions (which can operate on a lot of variables, even on HTTP headers) for granular matching and even external database lookups (either via plain text tables, DBM hash files or even external processes) for advanced URL substitution.
It operates on the full URLs (including the PATH_INFO part) both in per-server context (httpd.conf) and per-dir context (.htaccess) and even can generate QUERY_STRING parts on result. The rewriting result finally can lead to internal subprocessing, external request redirection or even to internal proxy throughput.
This module was originally written in April 1996 and gifted exclusively to the The Apache Software Foundation in July 1997 by
Ralf S. Engelschall
rse [at] engenschall.com
« Online Tool compares Packer, JSMin, Dojo, and YUI Compressor
COMPUTER SECURITY TOOLBOX »
Tags: cheatsheet, htaccess, mod_rewrite, mod_rewrite cheatsheet, rewritecond, rewriterule
The love of liberty is the love of others; the love of power is the love of ourselves.
-- William Hazlitt
Please consider donating to support active development of the free software and articles here.![]()
The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect. Tim Berners-Lee
Great! Thanks for this.
Really great!!! This is the best article I’ve ever read about mod_rewrite!!
Thanks a lot!!
Amazing work! Thanks a lot
It's very simple - you read the protocol and write the code. -Bill Joy
HTML | DCMI | GRDDL | XOXO | XDMP | XFN | DOM | XML | XHTML 1.1 Strict | CSS 2.1 | W3C | TLDP | WAI | DISA | ICSI | GIAC | SANS RR | GHOST | DEFCON | NIST | DHS CYBER | NIST | Phrack | GDB | IEEE | GIT | GNU LIBC
↑ TOPExcept where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. HTTPD based on NCSA HTTPd
What can i say,it is very good!