i have always used codigniter redirect function as
redirect('dashboard/index')
I have started a new project which is developed by someone else.
In that project if I use
redirect('dashboard/index')
it's redirecting to base_url();
but if i use redirect('dashboard/index') everything is working fine.
now the question is, how to solve this?
Its hard to check all redirect function and base_url() everywhere.
edit: I have added url helper on every controller.
It might be you have not supplied everything that $config['base_url'] needs. It should be a full URL complete with the protocol and ending in with a slash.
Try this.
$config['base_url'] = 'http://mywebsite.com/';
If you're using SSL then use https://mywebsite.com/
$redirect_url = base_url().'dashboard/index';
redirect($redirect_url);
Related
Due to my port 80 on my computer is blocked.
So I change my Apache config to change http port to 8899.
Problem here:
My original URL is http://localhost:8899/myProject/home
In controller, I use redirect function when user is not login:
redirect('login');
When I test this, the URL redirect to http://[::1]/myProject/login and show 404...
However, when I correct the URL to http://[::1]:8899/myProject/login by hand, it show the right page.
I want it redirect to http://[::1]:8899/myProject/login automatically.
Should I change any setting in config?
Thank you very much!
This will solve your issue.
Go to Config Folder -> Config.php
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].'/myProject/';
then use like below.
redirect(base_url('login'));
Change the base_url like this.
it will be easy and no need to change the code wh
$config['base_url'] = 'http://127.0.0.1:8080/appname/';
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.
On my local server, I have setup a website using Codeigniter which opens up fine using below URL
I have a different kind of query regarding rewriting URL
http://localhost/mywebsite
Actually the real URL is below
http://localhost/mywebsite/page/
Which I want it to work as root url as
http://localhost/mywebsite
So I have done it by adding it as default controller in config.php
But now I have another URL as
http://localhost/mywebsite/page/mypagename
Which should open as
http://localhost/mywebsite/mypagename
How can I do it?
You can define a custom route in /system/application/config/routes.php - for example:
$route['abc'] = 'controller_name/abc';
Then, http://mydemosite.com/abc
goes to http://mydemosite.com/controller_name/abc
see https://ellislab.com/codeigniter/user-guide/general/routing.html for more information of URI Routing.
I hope this can be helping you.
I got it solved using routing method as below under config/routes.php
$route['([^/]+)/?'] = 'page/$1';
URL mapping can be done at .htaccess and we can edit routes.php. Learning PHP/Codeigniter, i posted this question. CodeIgniter Mod Rewrite Rules and the Controller
routes.php worked for me, and the next thing i'd like is to have access to the GET parameters in my URL. To elaborate on what i'm actually trying to do:
Case 1:
RewriteRule ^([a-z]+)/(at)/([a-z]+)$ index.php/person/show?personName=$1&place=$2 [L]
This doesn't work at the .htaccess as in the above question, but I can get that working in the routes.php
$route['([a-z]+)/at/([a-z]+)'] = "person/show/$1/$2";
If i try the routes.php as
$route['([a-z]+)/at/([a-z]+)'] = "person/show?personName=$1&place=$2";
I end up with a CodeIgniter 404. Is this fundamentally incorrect?
This works fine as is:
person/show?personName=chinmay&place=kino
Case 2:
URL which I want to expose:
chinmay?place=kino
where place is shown as a GET param. I would like to handle this, and knowing as much about routes.php-
$route['([a-z]+)\?place=([a-z]+)'] = "person/show/$1/$2"
This gives a CI 404 as well.
Passing URI Segments to your Functions
or
GET parameters in the URL with CodeIgniter
You could use:
<?php
function myFunction($param1, $param2){
//code
}
?>
And access it like: .../controller/myFunction/param1/param2
I want both index.php included, and index.php excluded from my URIs to work smoothly on my site. I need it because of uploadify not working, and it is giving me a HTTP error.
It works if I have changed this
$config['uri_protocol'] = 'AUTO';
to this
$config['uri_protocol'] = 'QUERY_STRING';
, but then whole system is not working properly.
For your assets, first, on config.php set the $config['base_url'] to your website URL.
Then, when linking to assets on which you do NOT want index.php, just use the function base_url
<?php echo base_url("assets/uploadify/uploadify.swf"); ?>
// Generates http://URL/assets/uploadify/uploadify.swf
Follow the link in the comment from Indranil above to remove index.php from your URIs by modifying your .htaccess file.
Here is the address again for reference:
http://codeigniter.com/user_guide/general/urls.html
Keep in mind too that this can vary from host to host in the way that it needs to be formatted, so follow up on that with your hosting service. Most usually have guides that show you how to configure this properly.
I'd also like to know how you're using your links, but I'll go ahead and explain what I think may be happening to you. If you're doing any kind of link/anchor or redirect() using the URL Helper in CodeIgniter, then make sure you're using the right function to execute those actions. Here's what I mean:
The site_url() function/method will always include index.php in your URIs. Here's an example using the site name http://example.com as your website's domain.
<?php echo site_url('home') ?> will turn into http://example.com/index.php/home
While base_url() function/method will always exclude index.php unless you include it. Here's an example using the site name http://example.com as your website's domain.
<?php echo base_url('home') ?> will turn into http://example.com/home
and
<?php echo base_url('index.php/home') ?> will turn into http://example.com/index.php/home
Keep in mind that using these functions/methods are only effective AFTER you have properly modified your .htaccess file.
Here is the link that shows you a more in-depth difference between the site_url() and base_url() functions.
http://codeigniter.com/user_guide/helpers/url_helper.html
I hope this helps!