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
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access