Name
RewriteBase
Synopsis
RewriteBase BaseURL directory, .htaccess
The
effects of this command can be fairly easily achieved by using the
rewrite rules, but it may sometimes be simpler to encapsulate the
process. It explicitly sets the base URL for per-directory rewrites.
If RewriteRule
is used in an
.htaccess file, it is passed a URL that has had
the local directory stripped off so that the rules act only on the
remainder. When the substitution is finished,
RewriteBase
supplies the necessary prefix. To
quote the manual’s example in
.htaccess:
Alias /xyz /abc/def" RewriteBase /xyz RewriteRule ^oldstuff\.html$ newstuff.html
In this example, a request to /xyz/oldstuff.html gets rewritten to the physical file /abc/def/newstuff.html. Internally, the following happens:
- 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
Get Apache: The Definitive Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.