Anders
Anders

Reputation: 41

How to redirect users to another page?

I need to redirect users that visit a certain page without providing specific parameters in a query string. How to redirect users to another page the right way? So that the search engines would not penalize me for it.

Upvotes: 3

Views: 1905

Answers (4)

Pooja Khatri
Pooja Khatri

Reputation: 580

<?php
/* Redirect browser */
header("Location: http://www.google.com");
 
/* Make sure that code below does not get executed when we redirect. */
exit;
?>

Instead of http://www.google.com, you can write your own URL where you want to redirect your page.

Upvotes: 0

Jose
Jose

Reputation: 1

<?php
    Header("HTTP/1.1 302 Moved Temporarily"); 
    Header("Location: http://www.new-url.com");
    exit();
?> 

Upvotes: -1

dnagirl
dnagirl

Reputation: 20446

if($condition){
 header('Location: http://example.com');
 exit();
}

will do it. Don't forget the exit()!

Upvotes: 1

Daniel A. White
Daniel A. White

Reputation: 191058

<?php
    Header("HTTP/1.1 301 Moved Permanently"); 
    Header("Location: http://www.new-url.com");
    exit();
?> 

The moved permanently is what helps with search engines.

Upvotes: 11

Related Questions