urls - Redirect non existing page to frontpage

When a user type inn www.mypagex (which does not exist) the result show an empty body with the header and the footer in

When a user type inn www.mypage/x (which does not exist) the result show an empty body with the header and the footer intact. Most redirect plugins let me redirect one specific URL to another specific URL. What i want is to not only redirect a specific URL, but every non existing URL to a specific URL.

What does this redirecting action called, and how to i do that?

When a user type inn www.mypage/x (which does not exist) the result show an empty body with the header and the footer intact. Most redirect plugins let me redirect one specific URL to another specific URL. What i want is to not only redirect a specific URL, but every non existing URL to a specific URL.

What does this redirecting action called, and how to i do that?

Share Improve this question asked Jul 30, 2019 at 22:45 jan henriksenjan henriksen 11 bronze badge 1
  • Do you mean redirect on 404 not found? – Tom J Nowell Commented Jul 31, 2019 at 1:14
Add a comment  | 

1 Answer 1

Reset to default 2

You can use conditional tag is_404() and wp action hook to redirect whenever the page can not be found.

functions.php

add_action( 'wp', 'se344018_redirect_404' );
function se344018_redirect_404()
{
    if ( is_404() ) {
        wp_redirect( home_url() );
        //
        // wp_redirect( home_url('some/page-slug') );
        exit;
    }
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745281976a4620329.html

相关推荐

  • urls - Redirect non existing page to frontpage

    When a user type inn www.mypagex (which does not exist) the result show an empty body with the header and the footer in

    5小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信