I need to redirect my search results to a specific wordpress page based on a query string. I am getting a 'redirected too many times' error because the string is in the permalink of the new page. How can I get around this?

I have tried the .htaccess method of 301 redirecting via a query string but this applies the rule everywhere and to every search and I need this on the front end only.

Here is my code:

$words = array('lego','mario');

foreach($words as $word){
    if(stristr($_SERVER["REQUEST_URI"], $words) !== false) {
   wp_safe_redirect( site_url('lego-home' ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.