admin管理员组文章数量:1122846
Is there a way I can redirect the URL slug of the 404 template to /404/ so so for example if I have /category/media/blah it redirects to /404/
Is that possible I don't know if it can be done using .htaccess.
Ronny
Is there a way I can redirect the URL slug of the 404 template to /404/ so so for example if I have /category/media/blah it redirects to /404/
Is that possible I don't know if it can be done using .htaccess.
Ronny
Share Improve this question asked Jul 13, 2020 at 12:26 Rejaur RahmanRejaur Rahman 51 silver badge3 bronze badges 2 |2 Answers
Reset to default 0So you can do something like this:
- Open the
404.php
file and add these lines to the top of it. If you don't have one, create it. This will ensure WordPress uses this file for all permalinks that no longer exist or never existed.
<?php
/**
* Template Name: 404 Page
*/
$four_oh_four = get_permalink( get_page_by_path( '404' ) );
wp_redirect( $four_oh_four );
exit();
- Create a page with slug '404'.The above code will now redirect from the regular 404 template to a page with '404' slug.
I haven't tested it but should work.
Optionally, you could also use PHP's default redirection using headers if you want to. I just used WordPress' redirection API.
If you want to redirect to your Homepage, try something like this in the 404.php:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".get_bloginfo('url'));
exit();
?>
You can modify this to redirect to someurl.com.
本文标签: 404 errorRedirect to 404
版权声明:本文标题:404 error - Redirect to 404 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736292975a1929048.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
404
it'll update its index, but you want a redirect which is a301
. On top of that, your page titled/404
will return a200
code, not a404
code. Have you considered using the404.php
template that WP automatically loads on 404's instead? You don't need a page template and a page to style 404 errors – Tom J Nowell ♦ Commented Jul 13, 2020 at 14:06