- This topic has 4 replies, 3 voices, and was last updated 5 months, 1 week ago by Matthias.
May 17, 2020 at 4:58 am #1288382Matthias
i found a code that is said to make it possible to redirect 404page to home.
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: ".get_bloginfo('url')); exit(); ?>
Which makes me wonder – and is my questions:
is it possible to redirect 404 page/errors to a specific page (lets say a page called “error”)?
So you can create this page with gb – and have it a bit more shiny then the normal ones.
just tried a little:
<?php header("HTTP/1.1 301 Moved Permanently"); header("Location: http://www.example.com/error"); exit(); ?>
I created a 404.php in my child theme directory and added the text – and opening a non-existing page on my website redirect to the url entered above.
So this seems to work. Do you see any (security) problems with that code? I just grabbed it from a tutorial – and can’t code myself.May 17, 2020 at 5:28 am #1288412Thornbrand
There is a WordPress Plugin that does exactly this. It doesn’t require any coding, redirects, child theme templates, or additional server requests.
Just create a page and assign it as your custom 404 error page. Works very well.
Hope this helps!May 17, 2020 at 7:11 am #1288512Matthias
well – there is probably a plugin for everything. But personally i prefer a little code over that as in my experience a lot of plugins aren’t supported in the long run. I currently have to recreate a whole page because of this reason.
so – if it is as easy as creating a small 404.php with a little code in it – i’d prefer this a lot over.
Also – it seems the plugin doesn’t use gutenberg – while with the redirect code you can simple create a page with gutenberg.
But still – thx for your post – it’s always good to have options.
So the question still is if there may be any problems with that code when its used with gp? Or if there is a better solution for this theme.May 17, 2020 at 9:39 am #1288849LeoStaffCustomer Support
That plugin is what we usually suggest actually.
GP doesn’t do anything special for 404 page so if the code works for you then I don’t see any issues.
Can’t say about security though – this is something you’d need to check with the code authorMay 17, 2020 at 10:27 am #1288923Matthias
thx for the inport leo.
I actually just found that there is also i wp function for that.
So i replaced the former code with the customized example from wordpress.org.
<?php wp_redirect( 'http://www.example.com', 301 ); exit; ?>
Result is the same – but guess if there is a wp function i might as well use it.
- You must be logged in to reply to this topic.