I am making an API in PHP.
I want to add .json to the URL like this:
www.example.com/data.json
I am using CodeIgniter.
I have tried solving this in routes config file like this
$route['default_controller'] = 'data';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['/data.json'] = "/data/index";
You can add a url suffix in CodeIgniter by going to the config.php file and changing url_suffix:
$config['url_suffix'] = '.json';
This will make your website accesible via www.example.com/data and www.example.com/data.json
Check the documentation
If you want to enable it in some pages only you can use the routes like this:
$route['data.json'] = 'data/index';
If it's a page with dynamic path for example data/some-id.json use this:
$route['data/(:any).json'] = 'data/index/$1';
Related
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.
I am working on a project in codeigniter. I have stuck in baseurl when I run the controller then it includes all the files of jquery and css. But when I run a function then the url of the jquery add the name of the controller.
This is my base url: $config['base_url'] = 'http://localhost/cod_login/';
I don't know why codeigniter is doing that.
Base URL is wrong. It should be like this
$config['base_url'] = 'http://localhost/cod_login/';
$config['base_url'] = 'http://localhost/poject_name'; # syntax
$config['base_url'] = 'http://stackoverflow.com/'; # example
In Routes
$route['default_controller'] = "defult_controler_name";
$route['404_override'] = '';
this is happen when you don't echo base URL only (echo) is missing thanks to all for ans
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
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');
I am getting problem on codeigniter routing when routing url starts with variable like following -
$route['(:any)/(:any)'] = "home/index/0/N/DealsAmount/ASC/$1/$2";
i can to able to configure other routing url when i am passing values through url.
Example:
Following things work perfectly
$route['About-Us/Team'] = "aboutus/team";
$route['About-us/Jobs'] = "aboutus/jobs";
$route['About-Us/FAQ'] = "aboutus/faq";
But i use this url using varible like following --
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";
$route['About-us/Jobs/(:any)'] = "aboutus/jobs/$1";
$route['About-Us/FAQ/(:num)'] = "aboutus/faq/$1";
then it redirects to the home page that means this routing is not working here $route['(:any)/(:any)'] is working how can i able to rout these types of url can you please advise me.
You have to put the routes with :any at the bottom. If you put it at the top other routes never get caught. This should be OK:
$route['About-Us/Team/(:any)/(:any)'] = "aboutus/team/$1/$2";
$route['About-Us/Team/(:any)'] = "aboutus/team/$1";
$route['About-us/Jobs/(:any)'] = "aboutus/jobs/$1";
$route['About-Us/FAQ/(:num)'] = "aboutus/faq/$1";
$route['(:any)/(:any)'] = "home/index/0/N/DealsAmount/ASC/$1/$2";