[英]Redirect Wordpress Permalink in htaccess
I want to change the permalink structure of my site from /%postname%/ to /%category%/%post_id%/%postname%/, and have the old backlinks redirect to the new structure (currently getting 404's).我想将我网站的永久链接结构从 /%postname%/ 更改为 /%category%/%post_id%/%postname%/,并将旧的反向链接重定向到新结构(目前得到 404)。 I have tried a couple of different redirection plugins (Redirection, 301 Simple Plugins) and I can't get them to work.
我尝试了几个不同的重定向插件(重定向,301 简单插件),但我无法让它们工作。
Can someone show me the rule to put in the htaccess file instead?有人可以告诉我放入 htaccess 文件的规则吗?
Thanks!谢谢!
If you know the explicit category and post_id for a given postname, then you can create the redirects individually: 如果您知道给定帖子名称的显式类别和post_id,则可以单独创建重定向:
Redirect 301 /example-post-name-to-redirect/ /example-category/1234/example-post-name-to-redirect/
or using mod_rewrite (note, these rules must be before your wordpress rules: 或使用mod_rewrite(请注意,这些规则必须在您的wordpress规则之前 :
RewriteRule ^example-post-name-to-redirect/$ /example-category/1234/example-post-name-to-redirect/ [L,R=301]
But the better solution is just using wordpress to do this for you, have you tried: UrbanGiraffe Redirection plugin , Scott Yang's Permalink Redirect WordPress Plugin , or Yoast's Permalink Redirect WordPress Plugin ? 但是更好的解决方案是使用wordpress为您完成此操作,您是否尝试过: UrbanGiraffe重定向插件 , Scott Yang的Permalink Redirect WordPress插件或Yoast的Permalink重定向WordPress插件 ?
On the Redirection Wordpress Plugin you must add your old structure to Site->Permalink Migrations, something like this: /%year%/%monthnum%/%postname%/在重定向 Wordpress 插件上,您必须将旧结构添加到站点->永久链接迁移,如下所示:/%year%/%monthnum%/%postname%/
On the .htaccess file you must use regex like this one: RedirectMatch 301 /^/\d{4}/\d{2}/(.*) https://yourdomain.com/$1/在 .htaccess 文件上,您必须使用像这样的正则表达式: RedirectMatch 301 /^/\d{4}/\d{2}/(.*) https://yourdomain.com/$1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.