I have this website that works but once it is placed behind a load balancer, it gives a 502 error. After some troubleshooting, this snippet is the culprit.
if( function_exists( 'is_shop' ) && is_shop( ) ){
// $redirect_page_id = 132; // adjust to ID of page you are redirecting to */
wp_redirect( '/product-category/main-dish/' , 301 ); exit;
}
}
add_action( 'template_redirect', 'shop_redirect' );
I want the shop page, which is also the home page, to be a specific product archive page. Hence, I do a redirection. The above snippet works fine but once I added a load balancer, it fails to work. It returns a 502 error. I don't understand why it stops working behind a load balancer.
The error from load balancer is statusDetails: "failed_to_pick_backend"
What I am trying to is to have the product archive page to be the home page. The approach I attempted is to have the home page domain.com
to redirect to domain.com/product-category/main-dish/
I've tried many different ways to configure the load balancer and lost track of them. This is the current setting and I've tried with enabling and disabling the code snippet.
Just a recap:
- The website works correctly with the redirection snippet enabled.
- However, once it is placed behind a load balancer, it produces 502 error
- With a load balancer, there is no 502 error when the redirection snippet is disabled
- When the redirection snippet is enabled, it produces 502.