如果你也为大量的带“.html”后缀的url链接所困扰,那么这篇博文能帮助你,仅需简单三步,不需要一步步地创建重定向,不再让用户访问单调的404页面。 话不多说,我们立即开始。
# 重定向所有.html结尾的url
function redirect_html_to_slash() {
$request_uri = $_SERVER['REQUEST_URI'];
if (preg_match('/\.html$/', $request_uri)) {
$new_uri = preg_replace('/\.html$/', '/', $request_uri);
wp_redirect($new_uri, 301);
exit;
}
}
add_action('template_redirect', 'redirect_html_to_slash');
至此所有带”.html”后缀的url链接将会自动重定向到url链接。
GoSiteBoost将会持续不断地更新更多有关于建站以及SEO优化的教程,欢迎订阅GoSiteBoost邮件,接收更多更及时的教程。
仍有疑问?现在就 联系GoSiteBoost
Copyright © 2025 | GoSiteBoost | All Rights Reserved