From 96e44262b43dee19c7f11893e1257ed027363aa6 Mon Sep 17 00:00:00 2001 From: rboren Date: Wed, 2 Jun 2004 05:16:44 +0000 Subject: [PATCH] Rewrite rule fixes. git-svn-id: http://svn.automattic.com/wordpress/trunk@1381 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-blog-header.php | 1 + wp-includes/functions.php | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/wp-blog-header.php b/wp-blog-header.php index bc49ac1beb..684941680b 100644 --- a/wp-blog-header.php +++ b/wp-blog-header.php @@ -44,6 +44,7 @@ if (! empty($_SERVER['PATH_INFO'])) { // Parse the query. parse_str($query, $path_info); + break; } } } diff --git a/wp-includes/functions.php b/wp-includes/functions.php index a6d4bc0389..ec3ea77f98 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1174,7 +1174,7 @@ function preg_index($number, $matches = '') { return "$match_prefix$number$match_suffix"; } -function generate_rewrite_rules($permalink_structure = '') { +function generate_rewrite_rules($permalink_structure = '', $matches = '') { $rewritecode = array( '%year%', @@ -1199,7 +1199,7 @@ function generate_rewrite_rules($permalink_structure = '') { '([0-9]{1,2})', '([_0-9a-z-]+)', '([0-9]+)', - '(.*)', + '([/_0-9a-z-]+)', '([_0-9a-z-]+)' ); @@ -1267,7 +1267,7 @@ function generate_rewrite_rules($permalink_structure = '') { $match = $match . '?([0-9]+)?/?$'; $query = $index . '?' . $query . '&page=' . preg_index($num_toks + 1, $matches); } else { - $match .= '?'; + $match .= '?$'; $query = $index . '?' . $query; } @@ -1298,7 +1298,11 @@ function rewrite_rules($matches = '', $permalink_structure = '') { } } - $post_rewrite = generate_rewrite_rules($permalink_structure); + $post_rewrite = generate_rewrite_rules($permalink_structure, $matches); + + $feedregex = '(feed|rdf|rss|rss2|atom)/?$'; + $pageregex = 'page/?([0-9]{1,})/?$'; + $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); // If the permalink does not have year, month, and day, we need to create a // separate archive rule. @@ -1306,13 +1310,9 @@ function rewrite_rules($matches = '', $permalink_structure = '') { if (! (strstr($permalink_structure, '%year') && strstr($permalink_structure, '%monthnum') && strstr($permalink_structure, '%day')) ) { $doarchive = true; $archive_structure = $front . '%year%/%monthnum%/%day%/'; - $archive_rewrite = generate_rewrite_rules($archive_structure); + $archive_rewrite = generate_rewrite_rules($archive_structure, $matches); } - $feedregex = '(feed|rdf|rss|rss2|atom)/?$'; - $pageregex = 'page/?([0-9]{1,})/?$'; - $front = substr($permalink_structure, 0, strpos($permalink_structure, '%')); - // Site feed $sitefeedmatch = 'feed/?([_0-9a-z-]+)?/?$'; $sitefeedquery = 'index.php?feed=_' . preg_index(1, $matches); @@ -1338,20 +1338,22 @@ function rewrite_rules($matches = '', $permalink_structure = '') { $category_structure = get_settings('category_base') . '/'; $category_structure = $category_structure . '%category%'; - $category_rewrite = generate_rewrite_rules($category_structure); + $category_rewrite = generate_rewrite_rules($category_structure, $matches); // Authors $author_structure = $front . 'author/%author%'; - $author_rewrite = generate_rewrite_rules($author_structure); + $author_rewrite = generate_rewrite_rules($author_structure, $matches); // Put them together. - $rewrite = $site_rewrite + $category_rewrite + $author_rewrite + $post_rewrite; + $rewrite = $site_rewrite + $category_rewrite + $author_rewrite; // Add on archive rewrite rules if needed. if ($doarchive) { $rewrite = $rewrite + $archive_rewrite; } + $rewrite = $rewrite + $post_rewrite; + return $rewrite; }