Page redirecting in CodeIgniter

Page redirecting in CodeIgniter


  • Sometimes we need to redirect a page to another page in our project.
  • In native PHP, we use the header() method for redirection.
  • Codeigniter provides a redirect() method to redirect a page to another page.

Related Topics:

Codeigniter Interview Questions
Page caching in Codeigniter
Common functions in Codeigniter

Page Redirecting in CodeIgniter


redirect($uri = '', $method = 'auto', $code = NULL);

Parameter Description:

  • $uri (string) – this parameter represents the URI string. It has two possible values. It can be either a full site URL or a URI segment. It is mandatory.
  • $method (string) – This parameter represents the Redirect method. It has three possible values: 1. auto 2. location 3. refresh. By default, auto is selected. It is mandatory.
  • $code (string) – This parameter represents HTTP Response code (usually 302 or 303). It is an optional parameter.

The return type of this function is void.


Step 1 Open the application/controllers directory and create a new controller Redirect_controller.php.

class Redirect_controller extends CI_Controller {

public function index() {
/*Load the URL helper*/

/*Redirect the user to CodingTag site*/

public function codeigniter() {
/*Load the URL helper*/

redirect(''); //redirect to codeigniter tutorials on CodingTag

Step 2 Enter the given URL into the browser to redirect to your page on


Step 3 Enter the given URL to redirect your page on Codeigniter tutorials on


Best WordPress Hosting


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price

Leave a Reply

    Waiting for your comments