Ravichandran Jothi
Ravichandran Jothi

Reputation: 3066

Redirection not working in Wordpress?

I am using below code for redirection in wordpress

$currentPage = explode('?', $_SERVER ['REQUEST_URI']);
  $current_page_url = $currentPage[0];
 if($current_page_url == '/e-commerce')
    {
        header("Location : http://www.mysite.com/complete-e-commerce-solution",true);
    }

I am using this code in header.php, i am redirecting to third party site.is that problem?

Upvotes: 2

Views: 260

Answers (2)

Simon Scarfe
Simon Scarfe

Reputation: 9638

you need to follow the header call with an 'exit`. However, you might be better using wordpress's inbuilt wp_redirect function:

wp_redirect("Location : http://www.mysite.com/complete-e-commerce-solution");
exit;

Using wordpress functions allows plugins to filter the input and sanitises the input (not so applicable here, just good practice).

Upvotes: 3

filipe
filipe

Reputation: 1691

Any chance of getting /e-commerce from $currentPage[0]? The '/e-commerce' looks more like something that would be found at $currentPage[1].

Upvotes: 0

Related Questions