Redirecting with CodeIgniter

Can someone tell me why my redirection assistant doesn’t work as I expected? I am trying to redirect the index method of my primary controller, but I need www.mysite.com/index/provider1/ when it should go to www.mysite.com/provider1 . Does that make sense to everyone? My index page in config is set to empty, although I don't think this is a problem. Anyone have any tips to fix this problem? Thanks in advance!

controller

 if($provider == '') { redirect('/index/provider1/', 'location'); } 

.htaccess

 RewriteEngine on RewriteCond %{REQUEST_URI} !^(index\.php|files|images|js|css|robots\.txt|favicon\.ico) RewriteCond %{HTTP_HOST} ^mysite.com/ttnf/ RewriteRule (.*) http://www.mysite.com/ttnf/$1 [R=301,L] RewriteBase /ttnf/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] php_flag display_errors On 
+46
redirect php codeigniter
Apr 07 '09 at 1:39
source share
5 answers

redirects ()

URL Helper




The redirect operator in the code igniter sends the user to the specified web page using the redirect header instruction.

This statement is in the URL helper, which loads as follows:

 $this->load->helper('url'); 

The redirection function loads the local URI specified in the first parameter of the function call and is created using the options specified in your configuration file.

The second parameter allows the developer to use different HTTP commands to perform a "location" or "refresh" redirect.

According to Code Igniter documentation: "Location is faster, but on Windows servers this can sometimes be a problem."

Example:

 if ($user_logged_in === FALSE) { redirect('/account/login', 'refresh'); } 
+118
Apr 7 '09 at 11:27
source share
β€” -

If your directory structure looks like this,

 site application controller folder_1 first_controller.php second_controller.php folder_2 first_controller.php second_controller.php 

And when you are going to redirect it to the same controller in which you work, just write the following code.

  $this->load->helper('url'); if ($some_value === FALSE/TRUE) //You may give 0/1 as well,its up to your logic { redirect('same_controller/method', 'refresh'); } 

And if you want to redirect to another control, use the following code.

 $this->load->helper('url'); if ($some_value === FALSE/TRUE) //You may give 0/1 as well,its up to your logic { redirect('folder_name/any_controller_name/method', 'refresh'); } 
+3
Dec 20 '14 at 9:45
source share

If you want to redirect to a previous location or last request, you must include the user_agent library:

 $this->load->library('user_agent'); 

and then use, finally, in the function you use:

 redirect($this->agent->referrer()); 

his work is for me.

+2
Sep 28 '16 at 7:19
source share

Here is the .htacess file that hides the index file

 #RewriteEngine on #RewriteCond $1 !^(index\.php|images|robots\.txt) #RewriteRule ^(.*)$ /index.php/$1 [L] <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Removes index.php from ExpressionEngine URLs RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC] RewriteCond %{REQUEST_URI} !/system/.* [NC] RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L] # Directs all EE web requests through the site index file RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] </IfModule> 
0
Sep 28 '16 at 8:22
source share

firstly, you need to load a URL similar to this type, or you can load in the autoload.php file:

 $this->load->helper('url'); if (!$user_logged_in) { redirect('/account/login', 'refresh'); } 
0
Jul 20 '17 at 21:02
source share



All Articles