From a49296303c2a21e2bdaded18e3f8c946800431bf Mon Sep 17 00:00:00 2001
From: =?utf8?q?Igor=20Gali=C4=87?= 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:
- Status: Extension
- Module: mod_rewrite RewriteBase
directive specifies the
- URL prefix to be used for per-directory (htaccess)
- RewriteRule
directives that substitute a relative
- path.
-
- DocumentRoot
- (as opposed to reachable by other means, such as
- Alias
).RewriteRule
, suffixed by the relative
- substitution is also valid as a URL path on the server
- (this is rare).
In the example below, RewriteBase
is necessary
- to avoid rewriting to http://example.com/opt/myapp-1.2.3/welcome.html
- since the resource was not relative to the document root. This
- misconfiguration would normally cause the server to look for an "opt"
- directory under the document root.
The RewriteBase
directive explicitly
+ sets the base URL-path (not filesystem directory path!) for per-directory rewrites
+ that result in the substitution of a relative path.
+ When you use a RewriteRule
+ in a .htaccess
file, mod_rewrite
strips off
+ the local directory prefix before processing, then rewrites the rest of
+ the URL. When the rewrite is completed, mod_rewrite
+ automatically adds the local directory prefix (or the
+ RewriteBase
when set) back on to the substitution
+ before handing it back to the core of the server as if it were the original
+ URL.
This directive is required for per-directory rewrites whose context
+ is a directory made available via the Alias
+ directive, when the substitution uses a relative path.
If your URL path does not exist verbatim on the filesystem,
+ or isn't directly under your DocumentRoot
,
+ you must use RewriteBase
in every
+ .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/
-DocumentRoot /var/www/example.com -Alias /myapp /opt/myapp-1.2.3 -<Directory /opt/myapp-1.2.3> RewriteEngine On +# The URL-path used to get to this context, not the filesystem path RewriteBase /myapp/ -RewriteRule ^index\.html$ welcome.html -</Directory> +RewriteRule ^index\.html$ newsite.html