From 159875a751b4de99468e1d1c63cab3baaa4788d8 Mon Sep 17 00:00:00 2001 From: Eric Covener Date: Mon, 2 Apr 2012 12:37:32 +0000 Subject: [PATCH] PR51969: one more try at explaining RewriteBase, simplify the example and show how missing rewritebase altogether would go wrong. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1308320 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/mod/mod_rewrite.xml | 59 ++++++++++++++++----------------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml index 6dc853f500..9101e54222 100644 --- a/docs/manual/mod/mod_rewrite.xml +++ b/docs/manual/mod/mod_rewrite.xml @@ -293,42 +293,41 @@ Apache HTTP Server 2.0.41 and later FileInfo -

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/

+

The RewriteBase directive specifies the + URL prefix to be used for per-directory (htaccess) + RewriteRule directives that substitute a relative + path.

+

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: +

+

+ +

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.

+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$  newsite.html
+RewriteRule ^index\.html$  welcome.html 
+</Directory>
 
-
-- 2.40.0