本文整理汇总了PHP中redirect_guess_404_permalink函数的典型用法代码示例。如果您正苦于以下问题:PHP redirect_guess_404_permalink函数的具体用法?PHP redirect_guess_404_permalink怎么用?PHP redirect_guess_404_permalink使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了redirect_guess_404_permalink函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: redirect_canonical
/**
* Redirects incoming links to the proper URL based on the site url.
*
* Search engines consider www.somedomain.com and somedomain.com to be two
* different URLs when they both go to the same location. This SEO enhancement
* prevents penality for duplicate content by redirecting all incoming links to
* one or the other.
*
* Prevents redirection for feeds, trackbacks, searches, comment popup, and
* admin URLs. Does not redirect on IIS, page/post previews, and on form data.
*
* Will also attempt to find the correct link when a user enters a URL that does
* not exist based on exact WordPress query. Will instead try to parse the URL
* or query in an attempt to figure the correct page to go to.
*
* @since 2.3.0
* @uses $wp_rewrite
* @uses $is_IIS
*
* @param string $requested_url Optional. The URL that was requested, used to
* figure if redirect is needed.
* @param bool $do_redirect Optional. Redirect to the new URL.
* @return null|false|string Null, if redirect not needed. False, if redirect
* not needed or the string of the URL
*/
function redirect_canonical($requested_url = null, $do_redirect = true)
{
global $wp_rewrite, $is_IIS, $wp_query, $wpdb;
if (is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || isset($_POST) && count($_POST) || is_preview() || is_robots()) {
return;
}
if (!$requested_url) {
// build the URL in the address bar
$requested_url = is_ssl() ? 'https://' : 'http://';
$requested_url .= $_SERVER['HTTP_HOST'];
$requested_url .= $_SERVER['REQUEST_URI'];
}
$original = @parse_url($requested_url);
if (false === $original) {
return;
}
// Some PHP setups turn requests for / into /index.php in REQUEST_URI
// See: http://trac.wordpress.org/ticket/5017
// See: http://trac.wordpress.org/ticket/7173
// Disabled, for now:
// $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']);
$redirect = $original;
$redirect_url = false;
// Notice fixing
if (!isset($redirect['path'])) {
$redirect['path'] = '';
}
if (!isset($redirect['query'])) {
$redirect['query'] = '';
}
if (is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p'))) {
$vars = $wpdb->get_results($wpdb->prepare("SELECT post_type, post_parent FROM {$wpdb->posts} WHERE ID = %d", $id));
if (isset($vars[0]) && ($vars = $vars[0])) {
if ('revision' == $vars->post_type && $vars->post_parent > 0) {
$id = $vars->post_parent;
}
if ($redirect_url = get_permalink($id)) {
$redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']);
}
}
}
// These tests give us a WP-generated permalink
if (is_404()) {
// Redirect ?page_id, ?p=, ?attachment_id= to their respective url's
$id = max(get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id'));
if ($id && ($redirect_post = get_post($id))) {
$post_type_obj = get_post_type_object($redirect_post->post_type);
if ($post_type_obj->public) {
$redirect_url = get_permalink($redirect_post);
$redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id', 'post_type'), $redirect['query']);
}
}
if (!$redirect_url) {
$redirect_url = redirect_guess_404_permalink();
}
} elseif (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) {
// rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
if (is_attachment() && !empty($_GET['attachment_id']) && !$redirect_url) {
if ($redirect_url = get_attachment_link(get_query_var('attachment_id'))) {
$redirect['query'] = remove_query_arg('attachment_id', $redirect['query']);
}
} elseif (is_single() && !empty($_GET['p']) && !$redirect_url) {
if ($redirect_url = get_permalink(get_query_var('p'))) {
$redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']);
}
if (get_query_var('page')) {
$redirect_url = trailingslashit($redirect_url) . user_trailingslashit(get_query_var('page'), 'single_paged');
$redirect['query'] = remove_query_arg('page', $redirect['query']);
}
} elseif (is_single() && !empty($_GET['name']) && !$redirect_url) {
if ($redirect_url = get_permalink($wp_query->get_queried_object_id())) {
$redirect['query'] = remove_query_arg('name', $redirect['query']);
}
} elseif (is_page() && !empty($_GET['page_id']) && !$redirect_url) {
if ($redirect_url = get_permalink(get_query_var('page_id'))) {
//.........这里部分代码省略.........
示例2: redirect_canonical
/**
* Redirects incoming links to the proper URL based on the site url.
*
* Search engines consider www.somedomain.com and somedomain.com to be two
* different URLs when they both go to the same location. This SEO enhancement
* prevents penality for duplicate content by redirecting all incoming links to
* one or the other.
*
* Prevents redirection for feeds, trackbacks, searches, comment popup, and
* admin URLs. Does not redirect on IIS, page/post previews, and on form data.
*
* Will also attempt to find the correct link when a user enters a URL that does
* not exist based on exact WordPress query. Will instead try to parse the URL
* or query in an attempt to figure the correct page to go to.
*
* @since 2.3.0
* @uses $wp_rewrite
* @uses $is_IIS
*
* @param string $requested_url Optional. The URL that was requested, used to
* figure if redirect is needed.
* @param bool $do_redirect Optional. Redirect to the new URL.
* @return null|false|string Null, if redirect not needed. False, if redirect
* not needed or the string of the URL
*/
function redirect_canonical($requested_url=null, $do_redirect=true) {
global $wp_rewrite, $is_IIS, $wp_query, $wpdb;
if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || ( isset($_POST) && count($_POST) ) || is_preview() || is_robots() )
return;
if ( !$requested_url ) {
// build the URL in the address bar
$requested_url = ( !empty($_SERVER['HTTPS'] ) && strtolower($_SERVER['HTTPS']) == 'on' ) ? 'https://' : 'http://';
$requested_url .= $_SERVER['HTTP_HOST'];
$requested_url .= $_SERVER['REQUEST_URI'];
}
$original = @parse_url($requested_url);
if ( false === $original )
return;
// Some PHP setups turn requests for / into /index.php in REQUEST_URI
// See: http://trac.wordpress.org/ticket/5017
// See: http://trac.wordpress.org/ticket/7173
// Disabled, for now:
// $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']);
$redirect = $original;
$redirect_url = false;
// Notice fixing
if ( !isset($redirect['path']) ) $redirect['path'] = '';
if ( !isset($redirect['query']) ) $redirect['query'] = '';
if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) {
$vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) );
if ( isset($vars[0]) && $vars = $vars[0] ) {
if ( 'revision' == $vars->post_type && $vars->post_parent > 0 )
$id = $vars->post_parent;
if ( $redirect_url = get_permalink($id) )
$redirect['query'] = remove_query_arg(array('p', 'page_id', 'attachment_id'), $redirect['query']);
}
}
// These tests give us a WP-generated permalink
if ( is_404() ) {
$redirect_url = redirect_guess_404_permalink();
} elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) {
// rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
if ( is_single() && !empty($_GET['p']) && ! $redirect_url ) {
if ( $redirect_url = get_permalink(get_query_var('p')) )
$redirect['query'] = remove_query_arg('p', $redirect['query']);
if ( get_query_var( 'page' ) ) {
$redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
$redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
}
} elseif ( is_page() && !empty($_GET['page_id']) && ! $redirect_url ) {
if ( $redirect_url = get_permalink(get_query_var('page_id')) )
$redirect['query'] = remove_query_arg('page_id', $redirect['query']);
} elseif ( !empty($_GET['m']) && ( is_year() || is_month() || is_day() ) ) {
$m = get_query_var('m');
switch ( strlen($m) ) {
case 4: // Yearly
$redirect_url = get_year_link($m);
break;
case 6: // Monthly
$redirect_url = get_month_link( substr($m, 0, 4), substr($m, 4, 2) );
break;
case 8: // Daily
$redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2));
break;
}
if ( $redirect_url )
$redirect['query'] = remove_query_arg('m', $redirect['query']);
// now moving on to non ?m=X year/month/day links
} elseif ( is_day() && get_query_var('year') && get_query_var('monthnum') && !empty($_GET['day']) ) {
//.........这里部分代码省略.........
示例3: redirect_canonical
/**
* Redirects incoming links to the proper URL based on the site url.
*
* Search engines consider www.somedomain.com and somedomain.com to be two
* different URLs when they both go to the same location. This SEO enhancement
* prevents penalty for duplicate content by redirecting all incoming links to
* one or the other.
*
* Prevents redirection for feeds, trackbacks, searches, comment popup, and
* admin URLs. Does not redirect on IIS, page/post previews, and on form data.
*
* Will also attempt to find the correct link when a user enters a URL that does
* not exist based on exact WordPress query. Will instead try to parse the URL
* or query in an attempt to figure the correct page to go to.
*
* @since 2.3.0
* @uses $wp_rewrite
* @uses $is_IIS
*
* @param string $requested_url Optional. The URL that was requested, used to
* figure if redirect is needed.
* @param bool $do_redirect Optional. Redirect to the new URL.
* @return null|false|string Null, if redirect not needed. False, if redirect
* not needed or the string of the URL
*/
function redirect_canonical( $requested_url = null, $do_redirect = true ) {
global $wp_rewrite, $is_IIS, $wp_query, $wpdb;
if ( is_trackback() || is_search() || is_comments_popup() || is_admin() || !empty($_POST) || is_preview() || is_robots() || $is_IIS )
return;
if ( !$requested_url ) {
// build the URL in the address bar
$requested_url = is_ssl() ? 'https://' : 'http://';
$requested_url .= $_SERVER['HTTP_HOST'];
$requested_url .= $_SERVER['REQUEST_URI'];
}
$original = @parse_url($requested_url);
if ( false === $original )
return;
// Some PHP setups turn requests for / into /index.php in REQUEST_URI
// See: http://trac.wordpress.org/ticket/5017
// See: http://trac.wordpress.org/ticket/7173
// Disabled, for now:
// $original['path'] = preg_replace('|/index\.php$|', '/', $original['path']);
$redirect = $original;
$redirect_url = false;
// Notice fixing
if ( !isset($redirect['path']) )
$redirect['path'] = '';
if ( !isset($redirect['query']) )
$redirect['query'] = '';
if ( is_feed() && ( $id = get_query_var( 'p' ) ) ) {
if ( $redirect_url = get_post_comments_feed_link( $id, get_query_var( 'feed' ) ) ) {
$redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type', 'feed'), $redirect_url );
$redirect['path'] = parse_url( $redirect_url, PHP_URL_PATH );
}
}
if ( is_singular() && 1 > $wp_query->post_count && ($id = get_query_var('p')) ) {
$vars = $wpdb->get_results( $wpdb->prepare("SELECT post_type, post_parent FROM $wpdb->posts WHERE ID = %d", $id) );
if ( isset($vars[0]) && $vars = $vars[0] ) {
if ( 'revision' == $vars->post_type && $vars->post_parent > 0 )
$id = $vars->post_parent;
if ( $redirect_url = get_permalink($id) )
$redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
}
}
// These tests give us a WP-generated permalink
if ( is_404() ) {
// Redirect ?page_id, ?p=, ?attachment_id= to their respective url's
$id = max( get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id') );
if ( $id && $redirect_post = get_post($id) ) {
$post_type_obj = get_post_type_object($redirect_post->post_type);
if ( $post_type_obj->public ) {
$redirect_url = get_permalink($redirect_post);
$redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
}
}
if ( ! $redirect_url ) {
if ( $redirect_url = redirect_guess_404_permalink( $requested_url ) ) {
$redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url );
}
}
} elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) {
// rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
if ( is_attachment() && !empty($_GET['attachment_id']) && ! $redirect_url ) {
if ( $redirect_url = get_attachment_link(get_query_var('attachment_id')) )
//.........这里部分代码省略.........
示例4: redirect_canonical
//.........这里部分代码省略.........
if ('revision' == $vars->post_type && $vars->post_parent > 0) {
$id = $vars->post_parent;
}
if ($redirect_url = get_permalink($id)) {
$redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url);
}
}
}
// These tests give us a WP-generated permalink
if (is_404()) {
// Redirect ?page_id, ?p=, ?attachment_id= to their respective url's
$id = max(get_query_var('p'), get_query_var('page_id'), get_query_var('attachment_id'));
if ($id && ($redirect_post = get_post($id))) {
$post_type_obj = get_post_type_object($redirect_post->post_type);
if ($post_type_obj->public) {
$redirect_url = get_permalink($redirect_post);
$redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url);
}
}
if (get_query_var('day') && get_query_var('monthnum') && get_query_var('year')) {
$year = get_query_var('year');
$month = get_query_var('monthnum');
$day = get_query_var('day');
$date = sprintf('%04d-%02d-%02d', $year, $month, $day);
if (!wp_checkdate($month, $day, $year, $date)) {
$redirect_url = get_month_link($year, $month);
$redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('year', 'monthnum', 'day'), $redirect_url);
}
} elseif (get_query_var('monthnum') && get_query_var('year') && 12 < get_query_var('monthnum')) {
$redirect_url = get_year_link(get_query_var('year'));
$redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('year', 'monthnum'), $redirect_url);
}
if (!$redirect_url) {
if ($redirect_url = redirect_guess_404_permalink()) {
$redirect['query'] = _remove_qs_args_if_not_in_url($redirect['query'], array('page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type'), $redirect_url);
}
}
if (get_query_var('page') && $wp_query->post && false !== strpos($wp_query->post->post_content, '<!--nextpage-->')) {
$redirect['path'] = rtrim($redirect['path'], (int) get_query_var('page') . '/');
$redirect['query'] = remove_query_arg('page', $redirect['query']);
$redirect_url = get_permalink($wp_query->post->ID);
}
} elseif (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) {
// rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
if (is_attachment() && !array_diff(array_keys($wp->query_vars), array('attachment', 'attachment_id')) && !$redirect_url) {
if (!empty($_GET['attachment_id'])) {
$redirect_url = get_attachment_link(get_query_var('attachment_id'));
if ($redirect_url) {
$redirect['query'] = remove_query_arg('attachment_id', $redirect['query']);
}
} else {
$redirect_url = get_attachment_link();
}
} elseif (is_single() && !empty($_GET['p']) && !$redirect_url) {
if ($redirect_url = get_permalink(get_query_var('p'))) {
$redirect['query'] = remove_query_arg(array('p', 'post_type'), $redirect['query']);
}
} elseif (is_single() && !empty($_GET['name']) && !$redirect_url) {
if ($redirect_url = get_permalink($wp_query->get_queried_object_id())) {
$redirect['query'] = remove_query_arg('name', $redirect['query']);
}
} elseif (is_page() && !empty($_GET['page_id']) && !$redirect_url) {
if ($redirect_url = get_permalink(get_query_var('page_id'))) {
$redirect['query'] = remove_query_arg('page_id', $redirect['query']);
}
} elseif (is_page() && !is_feed() && isset($wp_query->queried_object) && 'page' == get_option('show_on_front') && $wp_query->queried_object->ID == get_option('page_on_front') && !$redirect_url) {
示例5: redirect_canonical
function redirect_canonical($requested_url = NULL, $do_redirect = true)
{
global $wp_rewrite, $posts, $is_IIS;
if (is_feed() || is_trackback() || is_search() || is_comments_popup() || is_admin() || $is_IIS || isset($_POST) && count($_POST)) {
return;
}
if (!$requested_url) {
// build the URL in the address bar
$requested_url = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on' ? 'https://' : 'http://';
$requested_url .= $_SERVER['HTTP_HOST'];
$requested_url .= $_SERVER['REQUEST_URI'];
}
$original = @parse_url($requested_url);
if (false === $original) {
return;
}
// Some PHP setups turn requests for / into /index.php in REQUEST_URI
$original['path'] = preg_replace('|/index\\.php$|', '/', $original['path']);
$redirect = $original;
$redirect_url = false;
// These tests give us a WP-generated permalink
if (is_404()) {
$redirect_url = redirect_guess_404_permalink();
} elseif (is_object($wp_rewrite) && $wp_rewrite->using_permalinks()) {
// rewriting of old ?p=X, ?m=2004, ?m=200401, ?m=20040101
if (is_single() && isset($_GET['p'])) {
if ($redirect_url = get_permalink(get_query_var('p'))) {
$redirect['query'] = remove_query_arg('p', $redirect['query']);
}
} elseif (is_page() && isset($_GET['page_id'])) {
if ($redirect_url = get_permalink(get_query_var('page_id'))) {
$redirect['query'] = remove_query_arg('page_id', $redirect['query']);
}
} elseif (isset($_GET['m']) && (is_year() || is_month() || is_day())) {
$m = get_query_var('m');
switch (strlen($m)) {
case 4:
// Yearly
$redirect_url = get_year_link($m);
break;
case 6:
// Monthly
$redirect_url = get_month_link(substr($m, 0, 4), substr($m, 4, 2));
break;
case 8:
// Daily
$redirect_url = get_day_link(substr($m, 0, 4), substr($m, 4, 2), substr($m, 6, 2));
break;
}
if ($redirect_url) {
$redirect['query'] = remove_query_arg('m', $redirect['query']);
}
// now moving on to non ?m=X year/month/day links
} elseif (is_day() && get_query_var('year') && get_query_var('monthnum') && isset($_GET['day'])) {
if ($redirect_url = get_day_link(get_query_var('year'), get_query_var('monthnum'), get_query_var('day'))) {
$redirect['query'] = remove_query_arg(array('year', 'monthnum', 'day'), $redirect['query']);
}
} elseif (is_month() && get_query_var('year') && isset($_GET['monthnum'])) {
if ($redirect_url = get_month_link(get_query_var('year'), get_query_var('monthnum'))) {
$redirect['query'] = remove_query_arg(array('year', 'monthnum'), $redirect['query']);
}
} elseif (is_year() && isset($_GET['year'])) {
if ($redirect_url = get_year_link(get_query_var('year'))) {
$redirect['query'] = remove_query_arg('year', $redirect['query']);
}
} elseif (is_category() && isset($_GET['cat'])) {
if ($redirect_url = get_category_link(get_query_var('cat'))) {
$redirect['query'] = remove_query_arg('cat', $redirect['query']);
}
} elseif (is_author() && isset($_GET['author'])) {
$author = get_userdata(get_query_var('author'));
if (false !== $author && ($redirect_url = get_author_link(false, $author->ID, $author->user_nicename))) {
$redirect['query'] = remove_query_arg('author', $redirect['author']);
}
}
// paging
if ($paged = get_query_var('paged')) {
if ($paged > 0) {
if (!$redirect_url) {
$redirect_url = $requested_url;
}
$paged_redirect = @parse_url($redirect_url);
$paged_redirect['path'] = preg_replace('|/page/[0-9]+?(/+)?$|', '/', $paged_redirect['path']);
// strip off any existing paging
$paged_redirect['path'] = preg_replace('|/index.php/?$|', '/', $paged_redirect['path']);
// strip off trailing /index.php/
if ($paged > 1 && !is_single()) {
$paged_redirect['path'] = trailingslashit($paged_redirect['path']);
if ($wp_rewrite->using_index_permalinks() && strpos($paged_redirect['path'], '/index.php/') === false) {
$paged_redirect['path'] .= 'index.php/';
}
$paged_redirect['path'] .= user_trailingslashit("page/{$paged}", 'paged');
} elseif (!is_home() && !is_single()) {
$paged_redirect['path'] = user_trailingslashit($paged_redirect['path'], 'paged');
}
$redirect_url = $paged_redirect['scheme'] . '://' . $paged_redirect['host'] . $paged_redirect['path'];
$redirect['path'] = $paged_redirect['path'];
}
$redirect['query'] = remove_query_arg('paged', $redirect['query']);
}
//.........这里部分代码省略.........