Codeigniter redirect doubles URL - php

I'm using codeigniter in localhost and I'm trying to redirect my controller to another controller, so what I basically do is:
redirect('/account/index');
However, it does not go to the URL, instead it goes here:
http://localhost/ticketsystem/index.php/logincheck/localhost/ticketsystem/index.php/account/index
It doubles my address. Do I need to set something in my config.php? My setup in my config.php is
$config['base_url'] = 'localhost/ticketsystem';
$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'AUTO';
Do I need to change something there, or am I doing something else that makes my redirect cause problems?

The base_url behaving like relative path, change into complete url, and also add '/' in last
$config['base_url'] = 'localhost/ticketsystem';
To
$config['base_url'] = 'http://localhost/ticketsystem/';

your base url should be looks like
$config['base_url'] = 'http://localhost/ticketsystem/';
use redirect like :-
redirect('account/index', 'refresh');
refresh will use meta refresh and should quick redirect

try removing the '/' before account!
redirect('account/index');

Related

Set Dynamic Base Url with Condition in Config Codeigniter

I need to set a dynamic base URL in Codeigniter due to few following reasons.
If IP using 10.3.1.77 change into HTTPS:
$config['base_url'] = "https://".$_SERVER['HTTP_HOST'].
str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
Else, change into HTTP:
$config['base_url'] = "https://".$_SERVER['HTTP_HOST'].
str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
But I have no idea how to identify the IP.
Any suggestions will be appreciated.
You can add a simple logic in config.php, remember application/config/config.php is a php script you can add any type of logic there!
try this out, edit the following code as per need.
$config['base_url'] = ($_SERVER['HTTP_HOST'] == 10.3.1.77 ? 'https' : 'http'). "://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

not getting proper base_url in codeigniter app

i am getting this type of url when trying to access pages other than index page
http://localhost:8012/health-care/8012//localhost/health-care/index.php/index.php/home
but url to access page must be
http://localhost:8012/health-care/index.php/home
my problem in url is: "it is duplicating url after "i hhttp://localhost:8012/healthcare/ that should not be duplicated.
i have autoloaded url helper in autoload.php as well as manually in constructor of controller. my base_url in conf
$config['base_url'] = 'http//localhost:8012/health-care/index.php/';
Guide me about this problem.
in addition to tell you that i have two app fron one codeigniter i.e. frontend and backend.
Url for backend works properly but for frontend its giving me mistakes what to do ?
$config['base_url'] = 'http//localhost:8012/health-care/';
used this base url you getting this url
http://localhost:8012/health-care/index.php/home
Y0u have to change this line
http://localhost:8012/health-care/index.php/home
to this
$config['base_url'] = 'http//localhost:8012/health-care/';
Please have a try.
Try this code:
$config['base_url'] = 'http://localhost:8012/health-care/';
and also make index_page as empty like this:
$config['index_page'] = '';
.htaccess file was not working. just replaced file and my problem got solved.

Redirect to my domain page

let me know how to redirect to main domain page in codeigniter. Like I want to Redirect my page to www.example.com from www.example.com/folder/controller/
Does anyone know?
First, get the url that the user is on
$url = $_SERVER['REQUEST_URI']; #www.example.com/folder/controller/
Second, you need to parse the url.
$parsedurl = parse_url($url);
Then, get the host.
$host = $parsedurl['host']; #www.example.com
Finally, redirect with redirect:
redirect($host);
I didn't test this, and it's pure php, which I assume will work, since I don't know anything about codeignighter
Edit 1: I changed header to redirect.
Edit 2: Forgot some semicolons ;)
Simply use redirect.
redirect('', 'refresh');
Also change
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
in application/config/config.php
Add .htaccess to remove index.php .
Refer official doc

Menu redirects only go to the index.php page with codeigniter

Codeigniter is a first for me so I hope I am clear in my explanation. In this case, I am dealing with setting up a Codeigniter website on a different server. I was getting forbidden access errors but have since corrected this, I think.
I've worked out the base url in config file to:
$config['base_url'] = 'http://websitename.com/';
and index_page is:
$config['index_page'] = '';
with the uri as:
$config['uri_protocol'] = 'AUTO';
The links from the menu are not redirecting properly. They simply reload the index page. In Firebug, this is what I see as one of the page links:
https://websitename.com/index.php?module/rekap_tl
Perhaps this is enough to understand the trouble here. I am working with this on a live server.
Any and all help is greatly appreciated.
you can configure codeigniter like
$config['base_url'] = ''; // Leave it empty so that codeigniter can guess it by itself, set $config['index_page'] = 'index.php'; and $config['uri_protocol'] = 'AUTO'; after that open application/config/autoload.php and then add url helper class to autoload helper $autoload['helper'] = array('url'); after that you can use in you menus "<?php echo base_url(); ?>index.php/controller/method/args" hope this may help

CodeIgniter unusual base URL

I want to set the base URL of my CodeIgniter installation to be localhost/ci/ with the trailing slash as advised in the documentation.
I try this:
$config['base_url'] = 'http://localhost/ci/';
And my pagination links are not what I would have expected. Basically,they are broken.
I, however, try this:
$config['base_url'] = 'http://localhost/ci/index.php/';
with this set
$config['index_page'] = 'index.php';
and my pagination links are now good. Is this,
$config['base_url'] = 'http://localhost/ci/index.php/';
the correct way of writing the base URL?
Remember one thing... Your base URL should be like
$config['base_url'] = 'http://localhost/ci/';
And your index URL will be
$config['index_page'] = 'index.php';
Then your site URL will be like
"http://localhost/ci/index.php"
And if you set the index URL empty like
$config['index_page'] = '';
then your site URL will be
"http://localhost/ci/"
So better at your paginations or anywhere you better use the site URL. You can get the site URL like:
echo site_url();
The site URL will be the combination of the base URL and the index URL:
site_url = base_url + index_url;

Categories