RewriteEngine
|
Enables or disables runtime rewriting engine.
Default: RewriteEngine off
Example 1: Usage.
|
X |
X |
X |
X |
RewriteCond
|
The RewriteCond directive defines a rule condition. Precede a RewriteRule directive
with one or more RewriteCond directives.
The RewriteRule directive will only take place if any one of the preceeding
RewriteConds evaluate as true.
TestString
Is usually an URL or part of it or can contains expanded constructs.
CondPattern
CondPattern is the condition pattern i.e., a regular expression which is applied
to the current instance of the TestString. The TestString is evaluated and then
matched against CondPattern.
CondPattern Flags
Special flags can be set by appending a third argument between "[ ]" to the RewriteCond directive.
If you wish to use multiple flags, you may delimit them by commas. The following flags can be used:
-
[NC]
No Case - Make the condition pattern case insensitive.
-
[OR]
OR condition - Allows a rule to apply if one of a series of conditions are true.
|
X |
X |
X |
X |
RewriteRule
|
The RewriteRule consists of a rewriting pattern and a url to redirect to.
Rule Flags
The rule flags can control the behaviour after a rewriting rule has been matched.
The following rule flags can be used:
-
[R] (force Redirect)
Redirect the to an external URL and send a 302 HTTP response (MOVED TEMPORARILY).
Note:
You can also do [R=301] to change the type. In this case a 301 HTTP response
is send. The following types can be given:
301 = Moved permanently
302 = Moved temporarily
403 = Forbidden
404 = Not found
410 = Gone
Example 1: Usage [R].
-
[F] (force URL to be Forbidden)
Force the current URL to be forbidden and send a 403 HTTP response (FORBIDDEN).
Example 1: Usage [F].
-
[G] (force URL to be Gone)
Force the current URL to be gone and send a 410 HTTP response (GONE).
Example 1: Usage [G].
-
[L] (last rule)
Force the rewriting proces to stop.
-
[P] (force proxy)
Force the current URL as a proxy request and put through the proxy module mod_proxy.
-
[N] (next round)
Rerun the rules again from the start.
-
[C] (chains)
Chains a rewrite rule together with the next rule.
-
[T=mime-type] (T MIME-type)
Use T MIME-type to force the file to be a mime type.
-
[NS] (no sub request)
Use if no sub request is requested.
-
[QSA] query string append
Use to add to an existing query string.
-
[NE] (no escapes)
Turns off normal escapes that are default in the rewriterule.
mod_rewrite escapes the # character into %23 which breaks the redirection.
-
[PT] (pass through)
Pass through to the handler (together with mod_alias).
-
[S=3] (skip)
Skip the next 3 rules.
-
[E=var:value]
Set environmental variable var to value.
|
X |
X |
X |
X |
RewriteLog
|
Logs any rewriting actions it performs.
If you do not want to use a log file, set the RewriteLogLevel to 0.
Default: -None-
LogFile
The logfile name where the rewrite actions are stored.
Example 1: Usage.
Example 2: LogFile output.
|
X |
X |
|
|
RewriteLogLevel
|
Set the verbosity level of the rewriting logfile. The higher the log level,
the more your server will be slowed by the logging process.
LogLevel
Level 0 = no logging
Level 9 = all actions are logged.
Default: RewriteLogLevel 0
Example 1: Usage.
|
X |
X |
|
|
RewriteBase
|
Uses the directory as the starting point for all URL's.
The directory must always start from the root directory.
RewriteBase /xyz/abc (correct)
RewiteBase xyz/abc (not correct)
Example 1: Usage.
|
|
|
X |
X |
RewriteOptions
|
Sets either the inherit or the MaxRedirects options for the current per-server or
per-directory configuration.
|
X |
X |
X |
X |
RewriteLock
|
Sets the file name for a synchronization lockfile,
which mod_rewrite needs to communicate with RewriteMap programs.
|
X |
|
|
|
RewriteMap
|
Defines a map, which can be used inside rule substitution strings
by the mapping functions to insert/substitute fields through a key lookup.
|
X |
X |
|
|
$N
|
RewriteRule backreferences
(0 <= N <= 9) which provide access to the grouped parts (parenthesis!)
of the pattern from the corresponding RewriteRule directive (the one following
the current bunch of RewriteCond directives).
|
%N
|
RewriteCond backreferences
(1 <= N <= 9) which provide access to the grouped parts (parentheses!)
of the pattern from the last matched RewriteCond directive in the current bunch
of conditions.
|
%{HTTP_USER_AGENT}
|
HTTP header: HTTP_USER_AGENT
Windows XP home edition, Firefox 1.07:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7
Windows XP home edition, Internet Explorer 6.0.29:
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Feedreader; .NET CLR 1.1.4322)
|
%{ HTTP_REFERER}
|
HTTP header: HTTP_REFERER
|
%{HTTP_COOKIE}
|
HTTP header: HTTP_COOKIE
|
%{HTTP_FORWARDED}
|
HTTP header: HTTP_FORWARDED
|
%{HTTP_HOST}
|
HTTP header: HTTP_HOST
If URL = https://www.mobilefish.com/home/index.html
HTTP_HOST is: www.mobilefish.com
|
%{HTTP_PROXY_CONNECTION}
|
HTTP header: HTTP_PROXY_CONNECTION
For example: text/xml, application/xml, application/xhtml+xml, text/html; q=0.9,
text/plain; q=0.8, image/png, */*; q=0.5
|
%{HTTP_ACCEPT}
|
HTTP header: HTTP_ACCEPT
|
%{REMOTE_ADDR}
|
Connection & Request: REMOTE_ADDR
|
%{REMOTE_HOST}
|
Connection & Request: REMOTE_HOST
|
%{REMOTE_USER}
|
Connection & Request: REMOTE_USER
|
%{REMOTE_IDENT}
|
Connection & Request: REMOTE_IDENT
|
%{REQUEST_METHOD}
|
Connection & Request: REQUEST_METHOD
|
%{SCRIPT_FILENAME}
|
Connection & Request: SCRIPT_FILENAME
|
%{PATH_INFO}
|
Connection & Request: PATH_INFO
|
%{QUERY_STRING}
|
Connection & Request: QUERY_STRING
|
%{AUTH_TYPE}
|
Connection & Request: AUTH_TYPE
|
%{DOCUMENT_ROOT}
|
Server Internals: DOCUMENT_ROOT
|
%{SERVER_ADMIN}
|
Server Internals: SERVER_ADMIN
|
%{SERVER_NAME}
|
Server Internals: SERVER_NAME
|
%{SERVER_ADDR}
|
Server Internals: SERVER_ADDR
|
%{SERVER_PORT}
|
Server Internals: SERVER_PORT
|
%{SERVER_PROTOCOL}
|
Server Internals: SERVER_PROTOCOL
|
%{SERVER_SOFTWARE}
|
Server Internals: SERVER_SOFTWARE
|
%{TIME_YEAR}
|
System Stuff: TIME_YEAR
|
%{TIME_MON}
|
System Stuff: TIME_MON
|
%{TIME_DAY}
|
System Stuff: TIME_DAY
|
%{TIME_HOUR}
|
System Stuff: TIME_HOUR
|
%{TIME_MIN}
|
System Stuff: TIME_MIN
|
%{TIME_SEC}
|
System Stuff: TIME_SEC
|
%{TIME_WDAY}
|
System Stuff: TIME_WDAY
|
%{TIME}
|
System Stuff: TIME
|
%{API_VERSION}
|
Specials: API_VERSION
|
%{THE_REQUEST}
|
Specials: THE_REQUEST
|
%{REQUEST_URI}
|
Specials: REQUEST_URI
|
%{IS_SUBREQ}
|
Specials: IS_SUBREQ
|
%{HTTPS}
|
Specials: HTTPS
|