Rewrite rule fixes.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1381 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rboren 2004-06-02 05:16:44 +00:00
parent 904c577e98
commit 96e44262b4
2 changed files with 15 additions and 12 deletions

View File

@ -44,6 +44,7 @@ if (! empty($_SERVER['PATH_INFO'])) {
// Parse the query. // Parse the query.
parse_str($query, $path_info); parse_str($query, $path_info);
break;
} }
} }
} }

View File

@ -1174,7 +1174,7 @@ function preg_index($number, $matches = '') {
return "$match_prefix$number$match_suffix"; return "$match_prefix$number$match_suffix";
} }
function generate_rewrite_rules($permalink_structure = '') { function generate_rewrite_rules($permalink_structure = '', $matches = '') {
$rewritecode = $rewritecode =
array( array(
'%year%', '%year%',
@ -1199,7 +1199,7 @@ function generate_rewrite_rules($permalink_structure = '') {
'([0-9]{1,2})', '([0-9]{1,2})',
'([_0-9a-z-]+)', '([_0-9a-z-]+)',
'([0-9]+)', '([0-9]+)',
'(.*)', '([/_0-9a-z-]+)',
'([_0-9a-z-]+)' '([_0-9a-z-]+)'
); );
@ -1267,7 +1267,7 @@ function generate_rewrite_rules($permalink_structure = '') {
$match = $match . '?([0-9]+)?/?$'; $match = $match . '?([0-9]+)?/?$';
$query = $index . '?' . $query . '&page=' . preg_index($num_toks + 1, $matches); $query = $index . '?' . $query . '&page=' . preg_index($num_toks + 1, $matches);
} else { } else {
$match .= '?'; $match .= '?$';
$query = $index . '?' . $query; $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 // If the permalink does not have year, month, and day, we need to create a
// separate archive rule. // 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')) ) { if (! (strstr($permalink_structure, '%year') && strstr($permalink_structure, '%monthnum') && strstr($permalink_structure, '%day')) ) {
$doarchive = true; $doarchive = true;
$archive_structure = $front . '%year%/%monthnum%/%day%/'; $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 // Site feed
$sitefeedmatch = 'feed/?([_0-9a-z-]+)?/?$'; $sitefeedmatch = 'feed/?([_0-9a-z-]+)?/?$';
$sitefeedquery = 'index.php?feed=_' . preg_index(1, $matches); $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 = get_settings('category_base') . '/';
$category_structure = $category_structure . '%category%'; $category_structure = $category_structure . '%category%';
$category_rewrite = generate_rewrite_rules($category_structure); $category_rewrite = generate_rewrite_rules($category_structure, $matches);
// Authors // Authors
$author_structure = $front . 'author/%author%'; $author_structure = $front . 'author/%author%';
$author_rewrite = generate_rewrite_rules($author_structure); $author_rewrite = generate_rewrite_rules($author_structure, $matches);
// Put them together. // 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. // Add on archive rewrite rules if needed.
if ($doarchive) { if ($doarchive) {
$rewrite = $rewrite + $archive_rewrite; $rewrite = $rewrite + $archive_rewrite;
} }
$rewrite = $rewrite + $post_rewrite;
return $rewrite; return $rewrite;
} }