Can anyone tell me why my redirect helper does not work the way I'd expect it to? I'm trying to redirect to the index method of my main controller, but it takes me www.mysite.com/index/provider1/
when it should route to www.mysite.com/provider1
. Does this make sense to anyone? I have index page in config set to blank, although I don't think that it is the issue. Does anyone have advice on how to fix this issue? 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
You can also check $this->input->is_ajax_request() but it's just an idea. That's it, now you have a history of visited URLs. You can change whatever you want, and then back(1). Also useful for redirect your users to whatever they were doing before login.
While building internet software, we regularly need to redirect the consumer from one page to another web page. CodeIgniter makes this job clean for us. The redirect () function is used for this reason.
site_url() : Returns your site URL, as specified in your config file. The index. php file (or whatever you have set as your site index_page in your config file) will be added to the URL, as will any URI segments you pass to the function, and the url_suffix as set in your config file.
This statement resides in the URL helper which is loaded in the following way:
$this->load->helper('url');
The redirect function loads a local URI specified in the first parameter of the function call and built using the options specified in your config file.
The second parameter allows the developer to use different HTTP commands to perform the redirect "location" or "refresh".
According to the Code Igniter documentation: "Location is faster, but on Windows servers it can sometimes be a problem."
Example:
if ($user_logged_in === FALSE) { redirect('/account/login', 'refresh'); }
If your directory structure is 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 in same controller in which you are working then 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 then 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'); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With