[英]Wordpress - Rewrite old URLs
We've changed our permalink-structure from /archive/%post_id%
to /%year%/%monthnum%/%postname%/
for better SEO. 我们将永久链接结构从
/archive/%post_id%
更改为/%year%/%monthnum%/%postname%/
以实现更好的SEO。
Now we have the problem, that all old URLs on Facebook for example are pointing to a 404 page. 现在我们有了问题,例如Facebook上的所有旧URL都指向404页面。
Is it possible to rewrite the old URLs to the new format? 是否可以将旧的URL重写为新的格式?
Added the following code to my themes functions.php 将以下代码添加到我的主题functions.php中
// Adding a new rule
/**
* Adds a new rewrite rule.
*
* @param array $rules Existing rewrite rules.
* @return array (Maybe) modified list of rewrites.
*/
function wpdocs_insert_rewrite_rules( $rules ) {
$newrules = array();
$newrules['archive/(\d*)$'] = 'index.php?postname=$matches[1]&post_id=$matches[2]';
return $newrules + $rules;
}
add_filter( 'rewrite_rules_array','wpdocs_insert_rewrite_rules' );
// Adding the id var so that WP recognizes it
function wpdocs_insert_query_vars( $vars ) {
array_push( $vars, 'id' );
return $vars;
}
add_filter( 'query_vars','wpdocs_insert_query_vars' );
Will be better to make redirection 301 from old to news. 将301从旧重定向到新闻会更好。 Several rules in the .htaccess should work.
.htaccess中的几个规则应该起作用。
I think you can use plugin "Simple 301 Redirects" to redirects from your old URLs to your new URLs. 我认为您可以使用插件“简单301重定向”将旧网址重定向到新网址。 You can dowload it at here https://wordpress.org/plugins/simple-301-redirects/
您可以在这里https://wordpress.org/plugins/simple-301-redirects/下载
If you need to 301 old URLs to the new, a WordPress plugin called 'Eggplant 301 Redirects' works really well. 如果您需要301旧的URL到新的URL,那么一个名为“ Eggplant 301 Redirects”的WordPress插件确实可以很好地工作。
https://wordpress.org/plugins/eps-301-redirects/ https://wordpress.org/plugins/eps-301-redirects/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.