admin管理员组文章数量:1188472
In WordPress 3.1 a post can be reached a number of ways, for example each one of these takes you to the same post (where /id is the base)
How can I tell WordPress to redirect all of these variations to
?
In WordPress 3.1 a post can be reached a number of ways, for example each one of these takes you to the same post (where /id is the base)
http://myblog.com/id/1008
http://myblog.com/id/1008/my-slug
http://myblog.com/my-slug
How can I tell WordPress to redirect all of these variations to
http://myblog.com/id/1008/my-slug
?
Share Improve this question edited Feb 14, 2012 at 20:27 nobody 2,4662 gold badges27 silver badges32 bronze badges asked Jun 5, 2011 at 20:35 qodeninjaqodeninja 4073 gold badges9 silver badges14 bronze badges5 Answers
Reset to default 2Check whether the posts not being redirected actually have the correct permalink stored in the DB. There's a bug in which canonicals can't be properly guessed because the permalink structure was CHANGED after the post was created.
Try either creating a new post with your current permalink structure, or editing the post_name DB field for them. (There's a plugin for updating the permalinks in DB)
The question remains. ASSUMING it is still happening:
How do we FORCE wordpress to REDIRECT to the canonical url? No just adding a link to it, but REDIRECTING to that page.
I changed the permalinks structure of the site, and added a add_rewrite_rule in functions.php, so now the old /02/20/2008/postname
addresses are accepted and canonicalized as /blob/postname
correctly… and the page is found successfully.
But no matter what I do, the canonical just stays as a link in the old URL'd page, still showing the wrong url in the adress bar.
NO REDIRECT is performed.
Ive worked with another website before, and I ended up (after days of trying tens of different pieces of code) using .htaccess redirects.
I know .htaccess redirects will work, but now that I read everywhere that "It should" be doing it… I'm wondering: Should it? and more exactly "how do I FORCE it?
WordPress should do this automatically. Whatever permalink format you have set in Settings > Permalinks should be the URL visitors end up at when they come to a different URL that indicates the same content.
I use a plugin called Redirection (http://urbangiraffe.com/plugins/redirection/) that allows me to set up rules for url redirection. This might suit your needs if you can't get WordPress to do what you want.
James :-)
wordpress does it automatically there is no need to do any thing if you have a custom structure defined in the settings->permalinks it will automatically redirect all the incoming structures to your custom structure or the one you have chosen in the settings in wp back end
/**
* Creates 301 redirects canonical
*/
function bm_redirect_can() {
// Is single Post
if ( is_single() ) {
global $wp;
$wp->parse_request();
$current_url = trim(home_url($wp->request), "/");
$redirect = get_permalink();
$surl = trim($redirect, "/");
if($current_url != $surl){
wp_redirect( $redirect, 301 );
exit;
}
}
}
add_action( 'template_redirect', 'bm_redirect_can' );
I got multiple emails about canonical issue. If I have 2 categories both category URL was indexed with proper one canonical tag and both pages able to access.
Example: https://www.blandmagazine.com/lifestyle/trendiest-messy-hair-buns/ https://www.blandmagazine.com/fashion/trendiest-messy-hair-buns/
This has not been automatically done by WP. Many paid plugins are available but programatically I have done above code and working.
本文标签: How can I force WordPress to redirect to canonical permalinks
版权声明:本文标题:How can I force WordPress to redirect to canonical permalinks? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738395390a2084477.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论