Changeset 5978
- Timestamp:
- 08/29/2007 09:06:51 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/canonical.php
r5974 r5978 3 3 4 4 function redirect_canonical() { 5 global $wp_rewrite, $posts ;5 global $wp_rewrite, $posts, $is_IIS; 6 6 7 if ( is_feed() || is_trackback() || is_search() || is_comments_popup() || is_admin() )7 if ( is_feed() || is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) ) 8 8 return; 9 9 … … 25 25 } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) { 26 26 // rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101 27 if ( is_single() && get_query_var('p') ) {27 if ( is_single() && isset($_GET['p']) ) { 28 28 if ( $redirect_url = get_permalink(get_query_var('p')) ) 29 29 $redirect['query'] = remove_query_arg('p', $redirect['query']); 30 } elseif ( is_page() && get_query_var('page_id') ) {30 } elseif ( is_page() && isset($_GET['page_id']) ) { 31 31 if ( $redirect_url = get_permalink(get_query_var('page_id')) ) 32 32 $redirect['query'] = remove_query_arg('page_id', $redirect['query']); 33 } elseif ( get_query_var('m') && ( is_year() || is_month() || is_day() ) ) {33 } elseif ( isset($_GET['m']) && ( is_year() || is_month() || is_day() ) ) { 34 34 $m = get_query_var('m'); 35 35 switch ( strlen($m) ) { … … 47 47 $redirect['query'] = remove_query_arg('m', $redirect['query']); 48 48 // now moving on to non ?m=X year/month/day links 49 } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && get_query_var('day') ) {49 } elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && isset($_GET['day']) ) { 50 50 if ( $redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day')) ) 51 51 $redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']); 52 } elseif ( is_month() && get_query_var('year') && get_query_var('monthnum') ) {52 } elseif ( is_month() && get_query_var('year') && isset($_GET['monthnum']) ) { 53 53 if ( $redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum')) ) 54 54 $redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']); 55 } elseif ( is_year() && get_query_var('year') ) {55 } elseif ( is_year() && isset($_GET['year']) ) { 56 56 if ( $redirect_url = get_year_link(get_query_var('year')) ) 57 57 $redirect['query'] = remove_query_arg('year', $redirect['query']); 58 } elseif ( is_category() && get_query_var('cat') ) {58 } elseif ( is_category() && isset($_GET['cat']) ) { 59 59 if ( $redirect_url = get_category_link(get_query_var('cat')) ) 60 60 $redirect['query'] = remove_query_arg('cat', $redirect['query']); 61 } elseif ( is_author() && get_query_var('author') ) {61 } elseif ( is_author() && isset($_GET['author']) ) { 62 62 $author = get_userdata(get_query_var('author')); 63 63 if ( false !== $author && $redirect_url = get_author_link(false, $author->ID, $author->user_nicename) ) … … 67 67 // paging 68 68 if ( $paged = get_query_var('paged') ) { 69 if ( $paged > 1) {69 if ( $paged > 0 ) { 70 70 if ( !$redirect_url ) 71 71 $redirect_url = $requested_url; 72 72 $paged_redirect = @parse_url($redirect_url); 73 $paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']); 74 $paged_redirect['path'] = trailingslashit($paged_redirect['path']); 75 if ( $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false ) 76 $paged_redirect['path'] .= 'index.php/'; 77 $paged_redirect['path'] .= user_trailingslashit("page/$paged"); 73 $paged_redirect['path'] = preg_replace('|/page/[0-9]+?/?$|', '/', $paged_redirect['path']); // strip off any existing paging 74 $paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']); // strip off trailing /index.php/ 75 if ( $paged > 1 && !is_singular() ) { 76 $paged_redirect['path'] = trailingslashit($paged_redirect['path']); 77 if ( $wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false ) 78 $paged_redirect['path'] .= 'index.php/'; 79 $paged_redirect['path'] .= user_trailingslashit("page/$paged", 'paged'); 80 } elseif ( !is_home() && !is_singular() ){ 81 $paged_redirect['path'] = user_trailingslashit($paged_redirect['path'], 'paged'); 82 } 78 83 $redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path']; 84 $redirect['path'] = $paged_redirect['path']; 79 85 } 80 86 $redirect['query'] = remove_query_arg('paged', $redirect['query']); … … 82 88 } 83 89 84 // tack on any additional query vars 85 if ( $redirect_url && $redirect['query'] ) { 86 if ( strpos($redirect_url, '?') !== false ) 87 $redirect_url .= '&'; 88 else 89 $redirect_url .= '?'; 90 $redirect_url .= $redirect['query']; 90 // tack on any additional query vars 91 if ( $redirect_url && $redirect['query'] ) { 92 if ( strpos($redirect_url, '?') !== false ) 93 $redirect_url .= '&'; 94 else 95 $redirect_url .= '?'; 96 $redirect_url .= $redirect['query']; 97 } 98 99 if ( $redirect_url ) 100 $redirect = @parse_url($redirect_url); 101 102 // www.example.com vs example.com 103 $user_home = @parse_url(get_option('home')); 104 $redirect['host'] = $user_home['host']; 105 106 // trailing /index.php or /index.php/ 107 $redirect['path'] = preg_replace('|/index.php/?$|', '/', $redirect['path']); 108 109 // strip /index.php/ when we're not using PATHINFO permalinks 110 if ( !$wp_rewrite->using_index_permalinks() ) 111 $redirect['path'] = str_replace('/index.php/', '/', $redirect['path']); 112 113 // trailing slashes 114 if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_home() || ( is_home() && (get_query_var('paged') > 1) ) ) ) { 115 $user_ts_type = ''; 116 if ( get_query_var('paged') > 0 ) { 117 $user_ts_type = 'paged'; 118 } else { 119 foreach ( array('single', 'category', 'page', 'day', 'month', 'year') as $type ) { 120 $func = 'is_' . $type; 121 if ( call_user_func($func) ) 122 $user_ts_type = $type; 123 break; 124 } 125 } 126 $redirect['path'] = user_trailingslashit($redirect['path'], $user_ts_type); 91 127 } 92 128 93 if ( !$redirect_url ) { // we're only going down this road if we don't have a WP-generated link from above 94 95 // www.example.com vs example.com 96 $user_home = parse_url(get_option('home')); 97 $redirect['host'] = $user_home['host']; 98 99 // trailing /index.php or /index.php/ 100 $redirect['path'] = preg_replace('|/index.php/?$|', '/', $redirect['path']); 101 102 // need to strip off the query string 103 if ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() && !is_404() && (!is_home() || ( is_home() && is_paged() ) ) ) 104 $redirect['path'] = user_trailingslashit($redirect['path']); 105 106 if ( array($original['host'], $original['path'], $original['query']) !== array($redirect['host'], $redirect['path'], $redirect['query']) ) { 107 $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; 108 if ( $redirect['query'] ) 109 $redirect_url .= '?' . $redirect['query']; 110 } 129 if ( array($original['host'], $original['path'], $original['query']) !== array($redirect['host'], $redirect['path'], $redirect['query']) ) { 130 $redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path']; 131 if ( $redirect['query'] ) 132 $redirect_url .= '?' . $redirect['query']; 111 133 } 112 134
Note: See TracChangeset
for help on using the changeset viewer.