I am looking for best method without any plugin that will redirect my homepage to category url. e.g
Main page: /
Direct redirect to this one.
Category URL: /
It helps me to reduce the servers response time.
I have readed many answers but not provided full guideline. Please briefly explain me which code will paste to which file. I have no experience of programming but work a little bit.
I am looking for best method without any plugin that will redirect my homepage to category url. e.g
Main page: https://uk49sresult.co.uk/
Direct redirect to this one.
Category URL: https://uk49sresult.co.uk/lunchtime-results/
It helps me to reduce the servers response time.
I have readed many answers but not provided full guideline. Please briefly explain me which code will paste to which file. I have no experience of programming but work a little bit.
Share Improve this question edited Jan 4, 2021 at 3:22 fuxia♦ 107k38 gold badges255 silver badges459 bronze badges asked Dec 9, 2020 at 12:10 49 ideas49 ideas 11 Answer
Reset to default 2You can use the following code:
add_action( 'request', function( $request ){
if( empty( $request ) ){
wp_safe_redirect( get_home_url() . '/lunchtime-results/' );
exit;
}
return $request;
});
This can be added to your theme's functions.php file.
The code checks the current request arguments. When visiting the home page the request is empty; in all other cases it would include some arguments.
So if the request is empty (is home page) it redirects to a new URL setting the HTTP status to 302(Found).