From: André Malo .htaccess file where you want to use RewriteRule directives.
The example below demonstrates how to map
- http://example.com/myapp/index.html to
- /home/www/example/newsite.html, in a .htaccess
- file. This assumes that the content available at
- http://example.com/ is on disk at
- /home/www/example/.
.htaccess file. This
+ assumes that the content available at
+ http://example.com/ is on disk at /home/www/example/
RewriteEngine On # The URL-path used to get to this context, not the filesystem path @@ -120,45 +119,47 @@ RewriteRule ^index\.html$ newsite.htmlStatus: Extension - Module: mod_rewrite The
- - -RewriteCond- directive defines a rule condition. One or moreRewriteCond- conditions can precede aRewriteRuledirective. The following rewrite rule is then - used only if these conditions are met, and if the URI matches the pattern - specified in the rule.-TestString
- -+
TestStringcan contain plain text, any of the - following expanded constructs, or both.The
+ +RewriteConddirective defines a + rule condition. One or moreRewriteCond+ can precede aRewriteRule+ directive. The following rule is then only used if both + the current state of the URI matches its pattern, and if these conditions are met.TestString is a string which can contain the + following expanded constructs in addition to plain text:
+
- RewriteRule backreferences: These are backreferences of the form
+ (0 <= N <= 9), which provide access to the grouped + parts (in parentheses) of the pattern, from the +$N- (1 <= N <= 9). They provide access to the grouped - parts of the currentRewriteRulepattern. The grouped - parts of the pattern are those in parentheses.RewriteRulewhich is subject to the current + set ofRewriteCondconditions. +- RewriteCond backreferences: These are backreferences of the form
+ (1 <= N <= 9), which provide access to the grouped + parts (again, in parentheses) of the pattern, from the last matched +%N- (1 <= N <= 9). They provide access to the grouped - parts of the last-matchedRewriteCondpattern. The - grouped parts of the pattern are those in parentheses.RewriteCondin the current set + of conditions. +- RewriteMap expansions: These are expansions of the form
${mapname:key|default}. - See the RewriteMap documentation - for more details. + See the documentation for + RewriteMap for more details.- - Server variables: These are variables of + Server-Variables: These are variables of the form -
%{ NAME_OF_VARIABLE }, - where NAME_OF_VARIABLE is one of the server variables from - the table below: - -+
%{NAME_OF_VARIABLE +}+ where NAME_OF_VARIABLE can be a string taken + from the following list: + +- -
HTTP headers: connection & request: @@ -227,23 +228,34 @@ RewriteRule ^index\.html$ newsite.html +The following variables are specific to -
+ +mod_rewrite:These variables all + correspond to the similarly named HTTP + MIME-headers, C variables of the Apache server or +
+struct tmfields of the Unix system. + Most are documented elsewhere in the Manual or in + the CGI specification. Those that are special to + mod_rewrite include those below.+ + -
- -
IS_SUBREQ- Contains the text "true" if the request - currently being processed is a sub-request, or +
- Will contain the text "true" if the request + currently being processed is a sub-request, "false" otherwise. Sub-requests may be generated by modules that need to resolve additional files or URIs in order to complete their tasks.
- -
API_VERSION- The version of the Apache module API contained in the - current httpd build, as defined in - include/ap_mmn.h.
+- This is the version of the Apache module API + (the internal interface between server and + module) in the current httpd build, as defined in + include/ap_mmn.h. The module API version + corresponds to the version of Apache in use (in + the release version of Apache 1.3.14, for + instance, it is 19990320:10), but is mainly of + interest to module authors.
- @@ -256,79 +268,108 @@ RewriteRule ^index\.html$ newsite.html
THE_REQUESTREQUEST_URI- The resource requested in the HTTP request - line.
+ line. (In the example above, this would be + "/index.html".)- -
REQUEST_FILENAME- The full local filesystem path of the file or +
- The full local filesystem path to the file or script matching the request.
- -
HTTPS- Contains the text "on" if the connection is - using SSL/TLS, or "off" otherwise. This variable - does not depend on
+mod_sslbeing loaded.- Will contain the text "on" if the connection is + using SSL/TLS, or "off" otherwise. (This variable + can be safely used regardless of whether or not +
mod_sslis loaded).Note that the
SCRIPT_FILENAMEand -REQUEST_FILENAME- variables both contain the value of the +Other things you should be aware of:
+ ++
- +
-The variables SCRIPT_FILENAME and REQUEST_FILENAME + contain the same value - the value of the
+filenamefield of the internal -request_recstructure. - If a substitution occurs and rewriting continues, - the value of both variables will be updated accordingly. - In a per-server context, before the - request is mapped to the filesystem, these variables contain the value - ofREQUEST_URI, because the full filesystem path is not - yet known. To obtain the full filesystem - path of a request in a per-server context, use a URL-based +request_recstructure of the Apache server. + The first name is the commonly known CGI variable name + while the second is the appropriate counterpart of + REQUEST_URI (which contains the value of the +urifield ofrequest_rec).If a substitution occurred and the rewriting continues, + the value of both variables will be updated accordingly.
+If used in per-server context (i.e., before the + request is mapped to the filesystem) SCRIPT_FILENAME and + REQUEST_FILENAME cannot contain the full local filesystem + path since the path is unknown at this stage of processing. + Both variables will initially contain the value of REQUEST_URI + in that case. In order to obtain the full local filesystem + path of the request in per-server context, use an URL-based look-ahead
+ the final value of REQUEST_FILENAME.%{LA-U:REQUEST_FILENAME}to determine - the final value ofREQUEST_FILENAME.Other available variables include the following:
--
- -
+%{ENV:variable}, where variable can be - any environment variable.- +
%{ENV:variable}, where variable can be + any environment variable, is also available. + This is looked-up via internal + Apache structures and (if not found there) via +getenv()from the Apache server process.- -
+ variable, can be used whether or not +%{SSL:variable}, where variable is the +%{SSL:variable}, where variable is the name of an SSL environment - variable. Ifmod_sslis not loaded, this - will always expand to the empty string.mod_sslis loaded, but will always expand to + the empty string if it is not. Example: +%{SSL:SSL_CIPHER_USEKEYSIZE}may expand to +128. +- -
+%{HTTP:header}, where header can be - any HTTP MIME-header name. For example, -%{HTTP:Proxy-Connection}is the value of the HTTP header - ``Proxy-Connection:''. If a HTTP header is used in a - condition, and the condition evaluates totrue, then that - header is added to the Vary header of the response. This is used to - ensure proper caching. - If a previous condition has evaluated totrueand the - 'ornext|OR' flag is in use, later - conditions are not evaluated, and therefore headers are not added to the - Vary header.%{HTTP:header}, where header can be + any HTTP MIME-header name, can always be used to obtain the + value of a header sent in the HTTP request. + Example:%{HTTP:Proxy-Connection}is + the value of the HTTP header + ``Proxy-Connection:''. +If a HTTP header is used in a condition this header is added to + the Vary header of the response in case the condition evaluates to + to true for the request. It is not added if the + condition evaluates to false for the request. Adding the HTTP header + to the Vary header of the response is needed for proper caching.
+It has to be kept in mind that conditions follow a short circuit + logic in the case of the '
+ornext|OR' flag + so that certain conditions might not be evaluated at all.- -
-%{LA-U:variable}, which is used to perform - an internal URL-based sub-request, to determine the final - value of variable. This can be used to access the value of - a variable which is to be set in a later phase. For example, the -REMOTE_USERvariable is set in the authorization phase of - processing. This comes after the URL translation phase, where rewrite - rules inhttpd.confare applied, but before the fixup - phase, where rewrite rules in a.htaccessfile are applied. - Therefore, to obtain the value of theREMOTE_USERvariable - withinhttpd.conf, you must use%{LA-U:REMOTE_USER}. To obtain the value of the -REMOTE_USERvariable within a.htaccessfile, - simply use%{REMOTE_USER}%{LA-U:variable}can be used for look-aheads which perform + an internal (URL-based) sub-request to determine the final + value of variable. This can be used to access + variable for rewriting which is not available at the current + stage, but will be set in a later phase. +For instance, to rewrite according to the +
+REMOTE_USERvariable from within the + per-server context (httpd.conffile) you must + use%{LA-U:REMOTE_USER}- this + variable is set by the authorization phases, which come + after the URL translation phase (during which mod_rewrite + operates).On the other hand, because mod_rewrite implements + its per-directory context (
+ +.htaccessfile) via + the Fixup phase of the API and because the authorization + phases come before this phase, you just can use +%{REMOTE_USER}in that context.- +
+ - -%{LA-F:variable}can be used to perform an internal + (filename-based) sub-request, to determine the final value + of variable. Most of the time, this is the same as + LA-U above.-diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml index 9151086b976..4e75300c1c8 100644 --- a/docs/manual/mod/mod_rewrite.xml +++ b/docs/manual/mod/mod_rewrite.xml @@ -500,11 +500,10 @@ once! module="mod_rewrite">RewriteRule directives.CondPattern
-CondPattern is the condition pattern, a regular expression which is applied to the current instance of the TestString. @@ -500,7 +541,6 @@ RewriteRule ^/$ /homepage.std.html [L] or your browser identifies itself as something non-standard), you get the std (standard) homepage.
-The example below demonstrates how to map -
+ http://example.com/myapp/index.html to + /home/www/example/newsite.html, in ahttp://example.com/myapp/index.htmlto -/home/www/example/newsite.html, in a.htaccess- file. This assumes that the content available at -http://example.com/is on disk at -/home/www/example/..htaccessfile. This + assumes that the content available at + http://example.com/ is on disk at /home/www/example/ RewriteEngine On @@ -529,46 +528,49 @@ RewriteRule ^index\.html$ newsite.htmlFileInfo - The
- -RewriteCond - directive defines a rule condition. One or moreRewriteCond - conditions can precede aRewriteRule directive. The following rewrite rule is then - used only if these conditions are met, and if the URI matches the pattern - specified in the rule.- TestString -+
TestStringcan contain plain text, any of the - following expanded constructs, or both.The
+ +RewriteCond directive defines a + rule condition. One or moreRewriteCond + can precede aRewriteRule + directive. The following rule is then only used if both + the current state of the URI matches its pattern, and if these conditions are met.TestString is a string which can contain the + following expanded constructs in addition to plain text:
+
- RewriteRule backreferences: These are backreferences of the form
+ (0 <= N <= 9), which provide access to the grouped + parts (in parentheses) of the pattern, from the +$N- (1 <= N <= 9). They provide access to the grouped - parts of the currentRewriteRulepattern. The grouped - parts of the pattern are those in parentheses.RewriteRulewhich is subject to the current + set ofRewriteCondconditions. +- RewriteCond backreferences: These are backreferences of the form
+ (1 <= N <= 9), which provide access to the grouped + parts (again, in parentheses) of the pattern, from the last matched +%N- (1 <= N <= 9). They provide access to the grouped - parts of the last-matchedRewriteCondpattern. The - grouped parts of the pattern are those in parentheses.RewriteCondin the current set + of conditions. +- RewriteMap expansions: These are expansions of the form
${mapname:key|default}. - See the RewriteMap documentation - for more details. + See the documentation for + RewriteMap for more details.- - Server variables: These are variables of + Server-Variables: These are variables of the form -
%{ NAME_OF_VARIABLE }, - where NAME_OF_VARIABLE is one of the server variables from - the table below: - -+
%{NAME_OF_VARIABLE +}+ where NAME_OF_VARIABLE can be a string taken + from the following list: + +- -
@@ -638,23 +640,34 @@ RewriteRule ^index\.html$ newsite.html The following variables are specific to -
+ +mod_rewrite :These variables all + correspond to the similarly named HTTP + MIME-headers, C variables of the Apache server or +
+struct tmfields of the Unix system. + Most are documented elsewhere in the Manual or in + the CGI specification. Those that are special to + mod_rewrite include those below.+ + + +
- -
IS_SUBREQ- Contains the text "true" if the request - currently being processed is a sub-request, or +
- Will contain the text "true" if the request + currently being processed is a sub-request, "false" otherwise. Sub-requests may be generated by modules that need to resolve additional files or URIs in order to complete their tasks.
- -
API_VERSION- The version of the Apache module API contained in the - current httpd build, as defined in - include/ap_mmn.h.
+- This is the version of the Apache module API + (the internal interface between server and + module) in the current httpd build, as defined in + include/ap_mmn.h. The module API version + corresponds to the version of Apache in use (in + the release version of Apache 1.3.14, for + instance, it is 19990320:10), but is mainly of + interest to module authors.
- @@ -667,78 +680,108 @@ RewriteRule ^index\.html$ newsite.html
THE_REQUESTREQUEST_URI- The resource requested in the HTTP request - line.
+ line. (In the example above, this would be + "/index.html".)- -
REQUEST_FILENAME- The full local filesystem path of the file or +
- The full local filesystem path to the file or script matching the request.
- -
HTTPS- Contains the text "on" if the connection is - using SSL/TLS, or "off" otherwise. This variable - does not depend on
+mod_ssl being loaded.- Will contain the text "on" if the connection is + using SSL/TLS, or "off" otherwise. (This variable + can be safely used regardless of whether or not +
mod_ssl is loaded).Other things you should be aware of:
-Note that the
SCRIPT_FILENAMEand -REQUEST_FILENAME- variables both contain the value of the ++
-- +
-The variables SCRIPT_FILENAME and REQUEST_FILENAME + contain the same value - the value of the
+filenamefield of the internal -request_recstructure. - If a substitution occurs and rewriting continues, - the value of both variables will be updated accordingly. - In a per-server context, before the - request is mapped to the filesystem, these variables contain the value - ofREQUEST_URI, because the full filesystem path is not - yet known. To obtain the full filesystem - path of a request in a per-server context, use a URL-based +request_recstructure of the Apache server. + The first name is the commonly known CGI variable name + while the second is the appropriate counterpart of + REQUEST_URI (which contains the value of the +urifield ofrequest_rec).If a substitution occurred and the rewriting continues, + the value of both variables will be updated accordingly.
+If used in per-server context (i.e., before the + request is mapped to the filesystem) SCRIPT_FILENAME and + REQUEST_FILENAME cannot contain the full local filesystem + path since the path is unknown at this stage of processing. + Both variables will initially contain the value of REQUEST_URI + in that case. In order to obtain the full local filesystem + path of the request in per-server context, use an URL-based look-ahead
+ the final value of REQUEST_FILENAME.%{LA-U:REQUEST_FILENAME}to determine - the final value ofREQUEST_FILENAME.Other available variables include the following:
-- +
- -
+%{ENV:variable}, where variable can be - any environment variable.- +
%{ENV:variable}, where variable can be + any environment variable, is also available. + This is looked-up via internal + Apache structures and (if not found there) via +getenv()from the Apache server process.- -
+ variable, can be used whether or not +%{SSL:variable}, where variable is the +%{SSL:variable}, where variable is the name of an SSL environment - variable. Ifmod_ssl is not loaded, this - will always expand to the empty string.mod_ssl is loaded, but will always expand to + the empty string if it is not. Example: +%{SSL:SSL_CIPHER_USEKEYSIZE}may expand to +128. +- -
+%{HTTP:header}, where header can be - any HTTP MIME-header name. For example, -%{HTTP:Proxy-Connection}is the value of the HTTP header - ``Proxy-Connection:''. If a HTTP header is used in a - condition, and the condition evaluates totrue, then that - header is added to the Vary header of the response. This is used to - ensure proper caching. - If a previous condition has evaluated totrueand the - 'ornext|OR' flag is in use, later - conditions are not evaluated, and therefore headers are not added to the - Vary header.%{HTTP:header}, where header can be + any HTTP MIME-header name, can always be used to obtain the + value of a header sent in the HTTP request. + Example:%{HTTP:Proxy-Connection}is + the value of the HTTP header + ``Proxy-Connection:''. +If a HTTP header is used in a condition this header is added to + the Vary header of the response in case the condition evaluates to + to true for the request. It is not added if the + condition evaluates to false for the request. Adding the HTTP header + to the Vary header of the response is needed for proper caching.
+It has to be kept in mind that conditions follow a short circuit + logic in the case of the '
+ornext|OR' flag + so that certain conditions might not be evaluated at all.- -
-%{LA-U:variable}, which is used to perform - an internal URL-based sub-request, to determine the final - value of variable. This can be used to access the value of - a variable which is to be set in a later phase. For example, the -REMOTE_USERvariable is set in the authorization phase of - processing. This comes after the URL translation phase, where rewrite - rules inhttpd.confare applied, but before the fixup - phase, where rewrite rules in a.htaccessfile are applied. - Therefore, to obtain the value of theREMOTE_USERvariable - withinhttpd.conf, you must use%{LA-U:REMOTE_USER}. To obtain the value of the -REMOTE_USERvariable within a.htaccessfile, - simply use%{REMOTE_USER}%{LA-U:variable}can be used for look-aheads which perform + an internal (URL-based) sub-request to determine the final + value of variable. This can be used to access + variable for rewriting which is not available at the current + stage, but will be set in a later phase. +For instance, to rewrite according to the +
+REMOTE_USERvariable from within the + per-server context (httpd.conffile) you must + use%{LA-U:REMOTE_USER}- this + variable is set by the authorization phases, which come + after the URL translation phase (during which mod_rewrite + operates).On the other hand, because mod_rewrite implements + its per-directory context (
+ +.htaccessfile) via + the Fixup phase of the API and because the authorization + phases come before this phase, you just can use +%{REMOTE_USER}in that context.- +
+%{LA-F:variable}can be used to perform an internal + (filename-based) sub-request, to determine the final value + of variable. Most of the time, this is the same as + LA-U above.- CondPattern CondPattern is the condition pattern, a regular expression which is applied to the current instance of the TestString. @@ -914,7 +957,6 @@ RewriteRule ^/$ /homepage.std.html [L] or your browser identifies itself as something non-standard), you get the std (standard) homepage.
-