ID=='') { $wp_query->set_404(); return; } $paged = abs($wp_query->get('paged')); if (!$wp_rewrite->using_permalinks()) { if ($paged > 1) { if ($page_of_posts===true) $link .= '&paged=' . $paged; else $link .= 'index.php?paged=' . $paged; } } else { if ($paged > 1) { if ($wp_rewrite->using_index_permalinks() && $page_of_posts===false) $link .= 'index.php/'; $link .= 'page/' . $paged . '/'; } } } if ($link != $page) { header('HTTP/1.1 301 Moved Permanently'); header('Status: 301 Moved Permanently'); header("Location: $link"); exit(0); } } else if ( is_category() ) { $cat_obj = $wp_query->get_queried_object(); if (!isset($cat_obj)) { $wp_query->set_404(); return; } $link = get_category_link($cat_obj->cat_ID); if (is_paged()) { if (count($posts) < 1 || $posts[0]->ID=='') { $wp_query->set_404(); return; } $paged = abs($wp_query->get('paged')); if (!$wp_rewrite->using_permalinks()) { if ($paged > 1) $link .= '&paged=' . $paged; } else { if ($paged > 1) $link .= 'page/' . $paged . '/'; } } if ($link!=$page) { header('HTTP/1.1 301 Moved Permanently'); header('Status: 301 Moved Permanently'); header("Location: $link"); exit(0); } } else if ( is_single() ) { if (count($posts) < 1 || $posts[0]->ID=='') { $wp_query->set_404(); return; } if (get_permalink($posts[0]->ID)!=$page) { $link = get_permalink($posts[0]->ID); header('HTTP/1.1 301 Moved Permanently'); header('Status: 301 Moved Permanently'); header("Location: $link"); exit(0); } } else if ( is_page() ) { if (count($posts) < 1 || $posts[0]->ID=='') { $wp_query->set_404(); return; } if (get_option('show_on_front')=='page' && get_option('page_on_front')==$posts[0]->ID) { // Static frontpage (WP 2.1+) if ($page!=(get_settings('home') . '/')) { $link = get_settings('home'); header('HTTP/1.1 301 Moved Permanently'); header('Status: 301 Moved Permanently'); header("Location: $link"); exit(0); } return; } if (get_page_link($posts[0]->ID)!=$page) { $link = get_page_link($posts[0]->ID); header('HTTP/1.1 301 Moved Permanently'); header('Status: 301 Moved Permanently'); header("Location: $link"); exit(0); } } else { return; // Unknown page-type (just pass it through) echo $_SERVER['REQUEST_URI']; exit(0); $wp_query->set_404(); return; } return; } function fix_request_uri_iis() { global $is_IIS; global $wp_rewrite; // Only IIS is having problem with REQUEST_URI if (!$is_IIS) return; // Should only fix REQUEST_URI for pages where the validator is used if (!permalink_validator_activate()) return; // IIS Mod-Rewrite if (isset($_SERVER['HTTP_X_ORIGINAL_URL'])) { $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL']; return; } // IIS Isapi_Rewrite if (isset($_SERVER['HTTP_X_REWRITE_URL'])) { $_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_REWRITE_URL']; return; } // Use ORIG_PATH_INFO if there is no PATH_INFO if ( !isset($_SERVER['PATH_INFO']) && isset($_SERVER['ORIG_PATH_INFO']) ) $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO']; // Simulate REQUEST_URI on IIS if (!empty($_SERVER['PATH_INFO']) && ($_SERVER['PATH_INFO'] == $_SERVER['SCRIPT_NAME'])) { // Some IIS and PHP combinations puts the same value in PATH_INFO and SCRIPT_NAME if ($wp_rewrite->using_permalinks()) $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME']; else $_SERVER['REQUEST_URI'] = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')) . '/'; } else { // SCRIPT_NAME includes script-path + script-filename if ($wp_rewrite->using_index_permalinks()) { // If root then simulate that no script-name was specified if (empty($_SERVER['PATH_INFO'])) $_SERVER['REQUEST_URI'] = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')) . '/'; else $_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] . $_SERVER['PATH_INFO']; } else { // If root then simulate that no script-name was specified if (empty($_SERVER['PATH_INFO'])) $_SERVER['REQUEST_URI'] = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')) . '/'; else $_SERVER['REQUEST_URI'] = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')) . $_SERVER['PATH_INFO']; } } // Append the query string if it exists and isn't null if (isset($_SERVER['QUERY_STRING']) && !empty($_SERVER['QUERY_STRING'])) { $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; } } // Fix for missing slash in category- and page-links when not having trailing slash in post permalink structure (WP 2.2+) function fix_user_trailingslashit($link, $type) { global $wp_rewrite; if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==false && $type != 'single') return trailingslashit($link); return $link; } if ( function_exists( 'add_filter' ) && function_exists('user_trailingslashit')) { add_filter('user_trailingslashit', 'fix_user_trailingslashit', 66, 2 ); } if ( function_exists( 'add_action' ) ) { add_action('template_redirect', 'permalink_validator'); add_action('init', 'fix_request_uri_iis'); } ?>