How to rewrite 404 to home page using htaccess?

I know how to do this using php, but need to redirect using htaccess.If I use this rule: ErrorDocument 404 index.php th

I know how to do this using php, but need to redirect using htaccess.

If I use this rule: ErrorDocument 404 /index.php then I still get the error page. Looks like wordpress identifies that this is 404 error and serves 404 message, not the homepage content as needed.

Any ideas?

I know how to do this using php, but need to redirect using htaccess.

If I use this rule: ErrorDocument 404 /index.php then I still get the error page. Looks like wordpress identifies that this is 404 error and serves 404 message, not the homepage content as needed.

Any ideas?

Share Improve this question asked Mar 16, 2017 at 14:03 dziunglesdziungles 11 silver badge1 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 2

There are a couple of ways to do this.

  1. If you're using a custom theme or a child theme, add (or edit) a theme file called 404.php. The contents of that file should be:

<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?>

  1. You can add this code as a plugin, or put it in your (custom or child) theme's functions.php file:

<?php function redirect_404s() { if(is_404()) { wp_redirect(home_url(), '301'); } } add_action('wp_enqueue_scripts', 'redirect_404s'); ?>

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

相关推荐

  • How to rewrite 404 to home page using htaccess?

    I know how to do this using php, but need to redirect using htaccess.If I use this rule: ErrorDocument 404 index.php th

    16小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

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

关注微信