From 9c308c6d52d9d15891aee34fc8f2522445ae816c Mon Sep 17 00:00:00 2001 From: Graham Leggett Date: Thu, 1 Dec 2011 12:46:40 +0000 Subject: [PATCH] Backport: mod_rewrite: Add the AllowNoSlash RewriteOption, which makes it possible for RewriteRules to be placed in .htaccess files that match the directory with no trailing slash. PR 48304. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1209057 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 5 +++++ docs/manual/mod/mod_rewrite.xml | 15 +++++++++++++++ modules/mappers/mod_rewrite.c | 9 +++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 1f61929bbc..bc8ab99f6e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,11 @@ -*- coding: utf-8 -*- Changes with Apache 2.4.0 + *) mod_rewrite: Add the AllowNoSlash RewriteOption, which makes it possible + for RewriteRules to be placed in .htaccess files that match the directory + with no trailing slash. PR 48304. + [Matthew Byng-Maddick ] + *) mod_session_crypto: Add a SessionCryptoPassphraseFile directive so that the administrator can hide the keys from the configuration. [Graham Leggett] diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml index c12df7f351..122d9ae741 100644 --- a/docs/manual/mod/mod_rewrite.xml +++ b/docs/manual/mod/mod_rewrite.xml @@ -171,6 +171,21 @@ later Available in Apache HTTP Server 2.3.10 and later.

+
AllowNoSlash
+
+

By default, mod_rewrite will ignore URLs that map to a + directory on disk but lack a trailing slash, in the expectation that + the mod_dir module will issue the client with a redirect to + the canonical URL with a trailing slash.

+ +

When the DirectorySlash directive + is set to off, the AllowNoSlash option can be enabled to ensure + that rewrite rules are no longer ignored. This option makes it possible to + apply rewrite rules within .htaccess files that match the directory without + a trailing slash, if so desired. Available in Apache HTTP Server 2.4.0 and + later.

+
+ diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 7d7e899eb4..470e01cdd3 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -189,6 +189,7 @@ static const char* really_last_key = "rewrite_really_last"; #define OPTION_NONE 1<<0 #define OPTION_INHERIT 1<<1 #define OPTION_INHERIT_BEFORE 1<<2 +#define OPTION_NOSLASH 1<<3 #ifndef RAND_MAX #define RAND_MAX 32767 @@ -2882,6 +2883,9 @@ static const char *cmd_rewriteoptions(cmd_parms *cmd, else if (!strcasecmp(w, "inheritbefore")) { options |= OPTION_INHERIT_BEFORE; } + else if (!strcasecmp(w, "allownoslash")) { + options |= OPTION_NOSLASH; + } else if (!strncasecmp(w, "MaxRedirects=", 13)) { ap_log_error(APLOG_MARK, APLOG_WARNING, 0, cmd->server, "RewriteOptions: MaxRedirects option has been " @@ -4698,9 +4702,10 @@ static int hook_fixup(request_rec *r) /* * .htaccess file is called before really entering the directory, i.e.: * URL: http://localhost/foo and .htaccess is located in foo directory - * Ignore such attempts, since they may lead to undefined behaviour. + * Ignore such attempts, allowing mod_dir to direct the client to the + * canonical URL. This can be controlled with the AllowNoSlash option. */ - if (!is_proxyreq) { + if (!is_proxyreq && !(dconf->options & OPTION_NOSLASH)) { l = strlen(dconf->directory) - 1; if (r->filename && strlen(r->filename) == l && (dconf->directory)[l] == '/' && -- 2.40.0