From: Eric Covener The When a substitution occurs for a new URL, this module has
- to re-inject the URL into the server processing. To be able
- to do this it needs to know what the corresponding URL-prefix
- or URL-base is. By default this prefix is the corresponding
- filepath itself. However, for most websites, URLs are NOT
- directly related to physical filename paths, so this
- assumption will often be wrong! Therefore, you can
- use the For example, assume the following per-directory config file: The This directive is required when you use a relative path
+ in a substitution in per-directory (htaccess) context unless either
+ of the following conditions are true:
+ .htaccess
). In such a case, it will act locally,
- stripping the local directory prefix before processing, and applying
- rewrite rules only to the remainder. When processing is complete, the
- prefix is automatically added back to the
- path. The default setting is; RewriteBase
directive to specify the
- correct URL-prefix..htaccess
-file where you want to use
+
+
In the example below,
-# -# /abc/def/.htaccess -- per-dir config file for directory /abc/def -# Remember: /abc/def is the physical path of /xyz, i.e., the server -# has a 'Alias /xyz /abc/def' directive e.g. -# - +DocumentRoot /var/www/example.com +Alias /myapp /opt/myapp-1.2.3 +<Directory /opt/myapp-1.2.3> RewriteEngine On - -# let the server know that we were reached via /xyz and not -# via the physical path prefix /abc/def -RewriteBase /xyz - -# now the rewriting rules -RewriteRule ^oldstuff\.html$ newstuff.html +RewriteBase /myapp/ +RewriteRule ^index\.html$ welcome.html +</Directory>
In the above example, a request to
- /xyz/oldstuff.html
gets correctly rewritten to
- the physical file /abc/def/newstuff.html
.
The following list gives detailed information about - the internal processing steps:
--Request: - /xyz/oldstuff.html - -Internal Processing: - /xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias) - /abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule) - /abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase) - /xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias) - -Result: - /abc/def/newstuff.html --
This seems very complicated, but is in fact - correct Apache internal processing. Because the - per-directory rewriting comes late in the - process, the rewritten request - has to be re-injected into the Apache kernel, as if it - were a new request. (See mod_rewrite technical - details.) - This is not the serious overhead it may seem to be - - this re-injection is completely internal to the - Apache server (and the same procedure is used by - many other operations within Apache).
-