From a85bbd647d26b9b7fa9479199b82534f5081d6d2 Mon Sep 17 00:00:00 2001 From: Ryan Boren 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: https://develop.svn.wordpress.org/trunk@1802 602fd350-edb4-49c9-b593-d223f7449a82 --- 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";