From cf34374c9c9f99343033f3de2ad02c1289433fab Mon Sep 17 00:00:00 2001 From: rboren Date: Fri, 15 Oct 2004 03:16:01 +0000 Subject: [PATCH] If the match is unanchored and greedy, prepend rewrite conditions to avoid infinite redirects and eclipsing of real files. Add L to rewrite flags to break out of rewriting once a match is found. git-svn-id: http://svn.automattic.com/wordpress/trunk@1802 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 952ae73143..301e860593 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1514,10 +1514,17 @@ function mod_rewrite_rules ($permalink_structure) { // Apache 1.3 does not support the reluctant (non-greedy) modifier. $match = str_replace('.+?', '.+', $match); + // If the match is unanchored and greedy, prepend rewrite conditions + // to avoid infinite redirects and eclipsing of real files. + if ($match == '(.+)/?$') { + $rules .= "RewriteCond %{REQUEST_FILENAME} !-f\n" . + "RewriteCond %{REQUEST_FILENAME} !-d\n"; + } + if (strstr($query, 'index.php')) { - $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA]\n"; + $rules .= 'RewriteRule ^' . $match . ' ' . $home_root . $query . " [QSA,L]\n"; } else { - $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA]\n"; + $rules .= 'RewriteRule ^' . $match . ' ' . $site_root . $query . " [QSA,L]\n"; } } $rules .= "\n";