mod_rewrite
Overview
mod_rewrite is the world-famous regular-expressions-based
URL manipulation engine that is now available for IIS users in the framework of Helicon Ape. It can:
- rewrite, redirect, proxy requests (see details)
- Rewriting causes server to continue request processing
with a new URL as if it has been originally requested by a client. New URL can
include query string section (following the question mark) and may point to
any plain static files, scripts (like ASP), programs (like EXE), etc. within
the same web application (which usually means the same web site). Rewriting
is completely transparent to the user and web site applications because it is
done internally on a server and before web application receives the request.
- Proxying causes the resulting URL to be internally
treated as a target on another server and immediately (i.e. rules processing
stops here) passed to the remote server. Response of the remote server will
then be passed back to the client. Proxy requires you to specify fully qualified
URL, starting from protocol, host name, etc.
- Redirection results in sending of immediate response
with a redirect instruction (HTTP response code 301 or 302) setting substituted
URL as a new location. You can use an absolute URL format (as required by RFC
2616) in redirection instruction to redirect the request to a different host,
port and protocol. If this information is omitted, mod_rewrite will automatically
prepend URL with the current request's protocol, server name and directory location.
- impose conditions on HTTP headers and query string values, server variables states etc.
- easily handle large sets of data with the help of mapfiles
- set/unset environment variables
- block access to specific hosts, referrers, pages
Quick start
Let's take a real-life example that is often requested/used by our customers.
Requested URL: http://www.site.com/index.asp?param1=valueM¶m2=valueN
Address bar: http://www.site.com/some_keyword
Content shown: http://www.site.com/index.asp?param1=valueM¶m2=valueN
Surely one usually needs to rewrite a large number of URLs of similar pattern (same parameters but different parameters' values),
hence map files are most suitable for this situation. So we need...
mapfile.txt
param1=value1¶m2=value2 keyword1
param1=value3¶m2=value4 keyword2
param1=value5¶m2=value6 keyword3
etc.
.htaccess
RewriteEngine on
RewriteBase /
#to use relative paths in RewriteMap, map files must reside in the same folder as .htaccess
RewriteMap mapfile txt:mapfile.txt [NC]
RewriteMap revmapfile txt_rev:mapfile.txt [NC]
RewriteCond %{QUERY_STRING} (.+)
RewriteRule ^index\.asp$ ${mapfile:%1}? [NC,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ index.asp?${revmapfile:$1} [NC,L,NS]
Related articles and topics
Examples
Simple search engine friendly URLs
This example demonstrates how to easily hide query string parameters using the loop (LP) flag.
Suppose you have a URL like http://www.mysite.com/foo.asp?a=A&b=B&c=C
and you want to access it as http://www.myhost.com/foo.asp/a/A/b/B/c/C. Here's the code you need:
RewriteEngine on
RewriteRule ^(.*?\.asp)/([^/]*)/([^/]*)(/.+)? $1$4?$2=$3 [NC,LP,QSA]
Note! This rule may break relative links to CSS, images, etc due to the change
of the base path (parent folder of the page). This problem occurs only if you use slash ('/')
as a replacement character. There are three possible solutions:
- Use another separator (see example below). It does not affect base path
- Explicitly specify correct base path for the page using <base href="/folder/page.asp"> tag
- Change all page-relative links to either root-relative or absolute form
Here's an example of using '~' separator (http://www.myhost.com/foo.asp~a~A~b~B~c~C) to get SEF URLs:
RewriteEngine on
RewriteRule ^(.*?\.asp)~([^~]*)~([^~]*)(.*) $1$4?$2=$3 [NC,LP,QSA]
Use IIS as reverse proxy
Assume you have the Internet server running IIS and several backend servers or
applications running other platform or machine. These servers are not directly
accessible from the Internet but you need to provide access to these servers
for others. Here is an example of how to simply map entire content of one web
site to the folder on another site:
RewriteEngine on
RewriteBase /
RewriteRule ^mappoint(.+)$ http://sitedomain$1 [NC,P]
Blocking inline-images (stop hot linking)
Assume you have some pages with inline .gif graphics under http://www.mysite.com/.
Some other sites incorporate this graphics via hyperlinks to their pages. This
adds useless traffic to your site and you want to stop this practice.
While you cannot 100% protect the images from inclusion using mod_rewrite—there's a
mod_hotlink module for that—you can at least check requests for which browser sends
HTTP Referer header. The following rules will only allow access to the images if referer is from the same host or empty:
RewriteEngine on
RewriteCond %{HTTP:Host}#%{HTTP:Referer} ^([^#]+)#(?!http://\1.*).+
RewriteRule .*\.(?:gif|jpg|png) /block.gif [NC]
Moving site location
It's a common task when you need to move the site from one domain name to another,
or just to another folder. So, it's necessary to redirect all requests from one web site
to another preserving the requested resource name and parameters. This is incredibly
useful especially when you want to preserve page rank of existing pages and
external links. The following configuration should be used on old web server:
RewriteEngine on
#Permanent redirect to update old links
RewriteRule (.+) http://newserver.com$1 [R=301]
Browser-dependent content
It may sometimes be necessary to provide browser-dependent content at least for
important top-level pages:
RewriteEngine on
RewriteBase /
#if Internet Explorer
RewriteCond %{HTTP:User-Agent} MSIE
RewriteRule ^foo\.htm$ foo.IE.htm [NC,L]
#if Mozilla
RewriteCond %{HTTP:User-Agent} (?:Lynx|Mozilla/[12])
RewriteRule ^foo\.htm$ foo.20.htm [NC,L]
#if any other browser
RewriteRule ^foo\.htm$ foo.32.htm [NC,L]
Dynamically generated robots.txt
robots.txt is a file that search engines use to discover URLs that
should or should not be indexed. But creation of this file for large sites with
lots of dynamic content can be a very complex task. Have you ever thought about
robots.txt dynamically generated from a script? Let's write robots.asp script:
<%@ Language=JScript EnableSessionState=False%>
<%
//The script must return plain text
Response.ContentType="text/plain";
/*
Place generation code here
*/
%>
Now make it available as robots.txt using a single mor_rewrite rule:
RewriteEngine on
RewriteBase /
RewriteRule ^robots\.txt$ robots.asp [NC,L]
Emulating load balancing
This example emulates some kind of DNS Round-Robin load balancing technique.
Suppose you have main site www.mysite.com and a number of web servers which
are registered as www[1-9].mysite.com If you install Ape on the
main server, you can spread traffic randomly between all servers by redirecting
initial client request to some specific server. Once redirected, client will
continue using this specific server. While this solution is not ideal, it can
really spread your traffic and help avoid problem with preserving session state.
RewriteEngine on
RewriteMap hosts rnd:hosts.txt
RewriteCond %{HTTP_HOST} (www)\.mysite\.com [NC]
RewriteRule (.*) http://${hosts:%1}.mysite.com$1 [R]
And here is the hosts.txt file content:
www www1|www2|www3|www4|www5|www6|www7|www8|www9
Blocking annoying robots
Here's the solution to get rid of lots of web-spiders:
RewriteCond %{HTTP:User-Agent} (?:WebBandit|2icommerce|\Accoona|ActiveTouristBot|adressendeutschland|aipbot|Alexibot|Alligator|
\AllSubmitter|\almaden|anarchie|Anonymous|Apexoo|Aqua_Products|asterias|\ASSORT|ATHENS|AtHome|Atomz|attache|autoemailspider|
autohttp|b2w|bew|\BackDoorBot|Badass|Baiduspider|Baiduspider+|BecomeBot|berts|Bitacle|Biz360|\Black.Hole|BlackWidow|
bladderfusion|BlogChecker|BlogPeople|BlogsharesSpiders|\Bloodhound|BlowFish|BoardBot|Bookmarksearchtool|BotALot|BotRightHere|
\Botmailto:craftbot@yahoo.com|Bropwers|Browsezilla|BuiltBotTough|Bullseye|\BunnySlippers|Cegbfeieh|CFNetwork|CheeseBot|
CherryPicker|Crescent|charlotte/|\ChinaClaw|Convera|Copernic|CopyRightCheck|cosmos|Crescent|c-spider|curl|Custo|\Cyberz|
DataCha0s|Daum|Deweb|Digger|Digimarc|digout4uagent|DIIbot|DISCo|DittoSpyder|\DnloadMage|Download|dragonfly|DreamPassport|
DSurf|DTSAgent|dumbot|DynaWeb|e-collector|\EasyDL|EBrowse|eCatch|ecollector|edgeio|efp@gmx.net|EirGrabber|EmailExtractor|
EmailCollector|\EmailSiphon|EmailWolf|EmeraldShield|Enterprise_Search|EroCrawler|ESurf|Eval|Everest-Vulcan|\Exabot|Express|
Extractor|ExtractorPro|EyeNetIE|FairAd|fastlwspider|fetch|FEZhead|FileHound|\findlinks|FlamingAttackBot|FlashGet|FlickBot|
Foobot|Forex|FranklinLocator|FreshDownload|\FrontPage|FSurf|Gaisbot|Gamespy_Arcade|genieBot|GetBot|Getleft|GetRight|GetWeb!|
Go!Zilla|\Go-Ahead-Got-It|GOFORITBOT|GrabNet|Grafula|grub|Harvest|HatenaAntenna|heritrix|HLoader|\HMView|holmes|HooWWWer|
HouxouCrawler|HTTPGet|httplib|HTTPRetriever|HTTrack|humanlinks|\IBM_Planetwide|iCCrawler|ichiro|iGetter|ImageStripper|
ImageSucker|imagefetch|imds_monitor|\IncyWincy|IndustryProgram|Indy|InetURL|InfoNaviRobot|InstallShieldDigitalWizard|
InterGET|\IRLbot|Iron33|ISSpider|IUPUIResearchBot|Jakarta|java/|JBHAgent|JennyBot|JetCar|jeteye|jeteyebot|JoBo|\JOCWebSpider|
Kapere|Kenjin|KeywordDensity|KRetrieve|ksoap|KWebGet|LapozzBot|larbin|leech|LeechFTP|\LeechGet|leipzig.de|LexiBot|libWeb|
libwww-FM|libwww-perl|LightningDownload|LinkextractorPro|Linkie|\LinkScan|linktiger|LinkWalker|lmcrawler|LNSpiderguy|LocalcomBot|
looksmart|LWP|MacFinder|MailSweeper|\mark.blonin|MaSagool|Mass|MataHari|MCspider|MetaProductsDownloadExpress|MicrosoftDataAccess|
MicrosoftURLControl|\MIDown|MIIxpc|Mirror|Missauga|MissouriCollegeBrowse|Mister|Monster|mkdb|moget|Moreoverbot|mothra/netscan|
\MovableType|Mozi!|Mozilla/22|Mozilla/3.0(compatible)|Mozilla/5.0(compatible;MSIE5.0)|MSIE_6.0|MSIECrawler|\MSProxy|MVAClient|
MyFamilyBot|MyGetRight|nameprotect|NASASearch|Naver|Navroad|NearSite|NetAnts|netattache|\NetCarta|NetMechanic|NetResearchServer|
NetSpider|NetZIP|NetVampire|NEWTActiveX|Nextopia|NICErsPRO|ninja|\NimbleCrawler|noxtrumbot|NPBot|Octopus|Offline|OKMozilla|
OmniExplorer|OpaL|Openbot|Openfind|OpenTextSiteCrawler|\OracleUltraSearch|OutfoxBot|P3P|PackRat|PageGrabber|PagmIEDownload|
panscient|PapaFoto|pavuk|pcBrowser|\perl|PerMan|PersonaPilot|PHPversion|PlantyNet_WebRobot|playstarmusic|Plucker|PortHuron|
ProgramShareware|\ProgressiveDownload|ProPowerBot|prospector|ProWebWalker|Prozilla|psbot|psycheclone|puf|PushSite|\PussyCat|
PuxaRapido|Python-urllib|QuepasaCreep|QueryN|Radiation|RealDownload|RedCarpet|RedKernel|\ReGet|relevantnoise|RepoMonkey|RMA|
Rover|Rsync|RTG30|Rufus|SAPO|SBIder|scooter|ScoutAbout|script|\searchpreview|searchterms|Seekbot|Serious|Shai|shelob|
Shim-Crawler|SickleBot|sitecheck|SiteSnagger|\SlurpyVerifier|SlySearch|SmartDownload|sna-|snagger|Snoopy|sogou|sootle|
So-net"bat_bot|SpankBot"bat_bot|\spanner"bat_bot|SpeedDownload|Spegla|Sphere|Sphider|SpiderBot|sproose|SQWebscanner|Sqworm|
Stamina|\Stanford|studybot|SuperBot|SuperHTTP|Surfbot|SurfWalker|suzuran|Szukacz|tAkeOut|TALWinHttpClient|\tarspider|
Teleport|Telesoft|Templeton|TestBED|TheIntraformant|TheNomad|TightTwatBot|Titan|\toCrawl/UrlDispatcher|True_Robot|turingos|
TurnitinBot|TwistedPageGetter|UCmore|UdmSearch|\UMBC|UniversalFeedParser|URLControl|URLGetFile|URLyWarning|URL_Spider_Pro|
UtilMind|vayala|\vobsub|VCI|VoidEYE|VoilaBot|voyager|w3mir|WebImageCollector|WebSucker|Web2WAP|WebaltBot|\WebAuto|WebBandit|
WebCapture|webcollage|WebCopier|WebCopy|WebEMailExtrac|WebEnhancer|WebFetch|\WebFilter|WebFountain|WebGo|WebLeacher|WebMiner|
WebMirror|WebReaper|WebSauger|WebSnake|Website|\WebStripper|WebVac|webwalk|WebWhacker|WebZIP|WellsSearch|WEPSearch00|WeRelateBot|
Wget|WhosTalking|\Widow|WildsoftSurfer|WinHttpRequest|WinHTTrack|WUMPUS|WWWOFFLE|wwwster|WWW-Collector|Xaldon|Xenu's|\Xenus|XGET|
Y!TunnelPro|YahooYSMcm|YaDirectBot|Yeti|Zade|ZBot|zerxbot|Zeus|ZyBorg) [NC]
RewriteRule .? - [F]
Directives
RewriteBase
When RewriteRule directive is used in per-directory
configuration files (.htaccess) it will automatically strip the local
directory prefix from the path and apply rules only to the remainder. RewriteBase
directive allows you to explicitly specify a base for the rules, i.e. the part
that will be stripped.
For directory context RewriteBase will be empty by default
but for .htaccess configurations it will contain virtual path to requested directory.
Syntax
RewriteBase URL-path
Default
RewriteBase requested-directory-path
Example
RewriteBase /
RewriteRule ^test\.asp$ index.htm [NC,L]
RewriteCond
RewriteCond directive defines a single condition for the following
RewriteRule, RewriteHeader or RewriteProxy directive.
Multiple conditions for the same rule are possible.
When several conditions are applied to the rule, by default, the rule fires when ALL of them get matched (AND logic).
If you want OR logic instead (at least one condition must match for the rule to fire), use [OR] flag.
Syntax
RewriteCond TestString CondPattern
Description
Flags
- NoCase or NC — makes the
CondPattern case-insensitive
- Ornext or OR — combines subsequent RewriteCond directives with logical OR instead
of implicit AND
- Optimize or O — normalizes string before processing (removes URL-encoding, illegal characters, etc; also, IIS normalization implies removal of query string from the URL)
Note! RewriteCond directive affects
only ONE subsequent RewriteRule, RewriteHeader
or RewriteProxy directive.
Example
# send all requests like www.domain.com/test.asp?id=123 to index.htm page
RewriteCond %{QUERY_STRING} ^id=(\d+)$
RewriteRule ^test\.asp$ index.htm? [NC,L]
RewriteEngine
RewriteEngine enables or disables rewriting runtime for the context it's specified in. Use RewriteEngine
off instead of commenting out rewrite rules if you need to disable mod_rewrite module or specific .htaccess file.
Syntax
RewriteEngine On|Off
Note! Unlike in ISAPI_Rewrite 3, it's necessary to specify RewriteEngine On directive to
make the config working.
RewriteHeader
RewriteHeader directive is a more general case of RewriteRule
directive; it's designed to rewrite not only the URL part of client request,
but any HTTP header. Technically RewriteRule directive
is equivalent to RewriteHeader URL: Pattern Substitution [flags].
This directive can be used to rewrite, create or delete any HTTP headers in
the client request before it is processed by other applications on IIS.
Syntax
RewriteHeader HeaderName: Pattern Substitution [flags]
Description
- HeaderName specifies the name of HTTP header that will be rewritten
- Pattern, Substitution and flags have the same meaning as for RewriteRule
directive
Note! RewriteHeader directive
has no equivalent in Apache (see Compatibility
chart).
RewriteLog
RewriteLog directive sets the name and path to the log file where mod_rewrite will log its actions.
Syntax
RewriteLog file-path
Example
RewriteLog "C:\local\path\rewrite.log"
RewriteLogLevel
RewriteLogLevel directive defines the verbosity of logging output.
The default value of 0 means no logging, while maximum level of 9 means all
actions will be logged.
Using higher values of logging may slow down mod_rewrite operation. We recommend
you to disable logging by setting log level to 0 after debugging of your ruleset
has been completed.
Syntax
RewriteLogLevel Level
Default
RewriteLogLevel 0
Example
RewriteLogLevel 9
RewriteMap
RewriteMap directive is used to define a key to value lookup
function. This is useful when you have to deal with large amount of values of similar pattern since it
is much faster than doing it with rule matching.
Syntax
RewriteMap MapName MapType:MapSource
Description
- MapName is the name of mapping function that will be used to refer
to this map from RewriteRule command. Make sure that
every mapping is given a unique name.
- MapType may be one of the following:
- txt — mapping using text file map
#plain text file
key1 value1
key2 value2
keyN valueN
- txt_rev — mapping using reverse text file map
#plain text map file with columns in reverse order
value1 key1
value2 key2
valueN keyN
- rnd — random value select from multiple choices
#one of the right column values is randomly selected
key1 value1|value2|value3
key2 value4|value5|value6|valueN
- int — internal functions
- toupper — converts the key to all upper case (not really necessary with the introduction of [NC] flag)
- tolower — converts the key to all lower case (not really necessary with the introduction of [NC] flag)
- escape — encode special characters to hex values
- unescape — unencode hex values to special characters
- dbd — mapping using external database
Example
Below is the example of how to use dbd-type map file to rewrite SEO-friendly URLs to original physical pages.
What you need is a database containing two columns: OriginalURL
(with real physical URLs) and SEO_URL (with pretty SEO-friendly links).
Having created the database you are ready to use this config:
DBDriver mssql
DBDParams "Data Source=server;Initial Catalog=database;User ID=user;Password=password"
DBDPrepareSQL "select OriginalURL from seo_mapping where `SEO_URL` =@KEY" seo_map_select
RewriteEngine On
RewriteMap map_dbd dbd:seo_map_select
RewriteCond ${map_dbd:$1|NOT_FOUND} (.*)
RewriteCond %1 !NOT_FOUND
RewriteRule (.+) %1 [L]
- MapSource is the path (absolute or relative) to the map file.
Flags
- NoCase or NC — makes the comparison of mapfile values with corresponding rule
submatch case-insensitive
You can call mapping function in the Substitution value of RewriteRule directive
using the following syntax:
${ MapName : LookupKey | DefaultValue }
If this construction is found in Substitution, mod_rewrite will lookup
for the key in the map file and if one is found, substitute the construct by
its value. If no key is found, optional DefaultValue will be used.
If no DefaultValue is specified, it will be substituted by an empty
string.
Example
RewriteMap examplemap txt:/path/to/file/map.txt [NC]
Then you may use this map in RewriteRule as follows:
RewriteRule ^/ex/(.*) ${examplemap:$1|0}
RewriteOptions
RewriteOptions directive sets special options for mod_rewrite.
Syntax
RewriteOptions Options
Currently only one option is available:
- inherit — forces current config to inherit all options and
rules from the parent. This means that all rules from the parent config will
be executed again but from the context as if they were written in the current
config.
Example
RewriteOptions inherit
RewriteProxy
RewriteProxy causes the resulting URL to be internally treated
as a target on another server and immediately (i.e. rules processing stops here)
passed to the remote server. Response of the remote server will then be passed
back to the client. Proxy requires you to specify fully qualified URL, starting
from protocol, host name, etc.
Syntax
RewriteProxy Pattern Substitution [flags]
Syntax of RewriteProxy is the same as of RewriteRule directive.
Flags
- A (Add authentication headers) — allows passing of an authentication information from proxy to an internal
server when client authentication against a proxy server is used. Proxy module will append headers
X-ISRW-Proxy-AUTH-TYPE,
X-ISRW-Proxy-AUTH-USER,
X-ISRW-Proxy-LOGON-USER,
X-ISRW-Proxy-REMOTE-USER
corresponding to server variables
AUTH_TYPE,
AUTH_USER,
LOGON_USER,
REMOTE_USER
to a request sent to a proxied server.
- CR (use CRedentials) — proxy module will try to login on a remote server with the credentials specified
in the URL or using basic authentication headers. With this flag you can use
http://user:password@host.com/path/ syntax
as a URL within substitution string.
Example
RewriteEngine On
RewriteBase /
RewriteProxy ^folder/(.*)$ http://www.google.com/$1
Note! RewriteProxy directive
has no equivalent in Apache (see Compatibility chart).
RewriteRule
RewriteRule directive defines a single URL rewriting operation.
Syntax
RewriteRule Pattern Substitution [flags]
Description
- Pattern — Perl-compatible regular expression which
will be matched against current URL. The current URL may be either originally requested
URL or URL already altered by preceding rules. URL never includes protocol,
host name and port number (they are defined in RewriteCond if necessary).
Note! The current URL may differ
depending on the location of configuration file—for directory level
configurations current directory name is substracted from the URL to match.
Please address Regular expression syntax section
of the documentation for more information on building regular expressions.
Preceding pattern by a ! character will negate entire expression. Negated
pattern cannot generate submatches so you cannot use $N references in substitution.
- Substitution — specifies format string to generate
new URL if the Pattern is matched. In addition to plain text it can include:
- back references to RewriteRule pattern: $N ($0-$9) and $$NN ($$10-$$99)
- back references to RewriteCond pattern: %N (%0-%9) and %%NN (%%10-%%99)
- map files calls %{mapname:key|default}
- server variables %{VARNAME}
- environment variables %{ENV:variable}
- conditional format patterns (?Ntrue_string:false_string)
- grouping parenthesis ‘(‘ and ‘)’
The syntax also allows escape sequences...
- \a — the bell character
- \f — the form feed character
- \n — the newline character
- \r — the carriage return character
- \t — the tab character
- \v — the vertical tab character
- \x — the hexadecimal character - for example \x0D
- \x{} — possible Unicode hexadecimal character - for example \x{1A0}
- \cx — the ASCII escape character x, for example \c@ is equivalent to escape-@
- \e — the ASCII escape character
- \dd — the octal character constant, for example \10
- \\ — single back slash character '\'
RewriteRule directives are applied in order of appearance in configuration
file, starting from the parent configuration files. Each rule will apply only
if its Pattern matches reuqested URL and all related conditions
(RewriteCond) are also matched.
Special string '-' (dash) in Substitution means no substitution
and is useful when you need to apply the rule but perform no actions (leave original URL intact).
Example
RewriteEngine On
#do nothing when requested resource is either physical file or folder
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .? - [L]
Flags
- CaseLower or CL — changes the case of substitution result to lower
- CaseUpper or CU — changes the case of substitution result to upper
- Chain or C — chains current rule with the next rule. Next rule will be executed only if the
current rule is matched. Chain may contain more than 2 rules
- Cookie or CO=NAME:VAL:domain[:lifetime[:path]] — sets cookie header with the fields specified and sends it to the client in
response to the current request
- Env or E=VAR:VAL — sets an environment variable
- Forbidden or F — sends immediate 403 Forbidden response to the client; stops rules processing
and all other subsequent processing on this request
- Gone or G — sends immediate 410 Gone response to the client; stops rules processing and
all other subsequent processing on this request
- Handler or H=Content-handler — unsupported. Explicitly specifies handler for a request. In IIS world this
can be achieved by rewriting file extension of requested file but there is
no direct translation from Apache handlers to IIS file extensions
- Last or L — stops rewriting process here and doesn't apply any more rules from the
current configuration file. Descendant .htaccess files will still be applied if any
- Loop or LP — re-runs current single rule in the loop while its pattern and conditions
are matched. Number of iterations is limited to a value of 200 to avoid infinite loops
- Next or N — re-runs entire rewriting process starting from the beginning of current configuration
file. Number of iterations is limited to a value of 200 to avoid infinite loops
- NoCase or NC — makes the
Pattern case-insensitive
- NoEscape or NE — prevents mod_rewrite from applying the usual URI escaping rules to the rewriting result.
With this flag special characters (e.g. '%', '$', ';', etc) will NOT be escaped into their
hexcode equivalents ('%25', '%24', '%3B' respectively)
- NoSubreq or NS — forces rewriting engine to skip a rule if the current request is an internal sub-request.
Supported only in IIS7.
- nOrmalize or O — normalization includes removing of an URL-encoding, illegal characters, etc.;
also normalization of URL completely removes query string from it. When O flag is not set,
normalization takes place. If you set O at the end of the rule, normalization will not occur
- Proxy or P — forces the resulting URL to be internally treated as a target on another server
and immediately passed to the remote server
- PassThrough or PT — unsupported or always on. Result is always passed through the next handler
in IIS
- QSAppend or QSA — appends query string of the original request to the
Substitution string
(regardless of whether Substitution has new query string or not). It may be useful when you need add new query string parameters
but also preserve the originally requested ones
- Redirect or R[=code] — forces server to send immediate response with redirect instruction,
providing
Substitution as a new location. You can optionally prefix Substitution
with http://thishost[:thisport]/ bringing URL to a valid absolute form. If
no code is specified, 302 (Moved Temporarily) response will be used by default.
You can optionally specify any code from 3xx range
- Skip or S=num — forces rewriting engine to skip the next
num rules in sequence, if the
current rule matches
- StatusCode or SC=200..500 — forces server to send immediate response with custom status code page
- Type or T=MIME-type — forces 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
- Unmanglelog or U — logs the URL as it was originally requested and not as the URL
was rewritten