The CodeIgniter Routing dont work,
Im trying to route:
$route['Kayit'] = "Kayit/index";
localhost:8090/Kayit/ result = 404 Page Not Found
And it doesnt work. Can someone help me?
My route.php file:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['default_controller'] = 'Sayfa/view';
$route['(:any)'] = 'Sayfa/view/$1';
$route['Sayfa/'] = 'Sayfa/view/';
$route['Kayit/'] = "Kayit/index";
?>
Put
$route['(:any)'] = 'Sayfa/view/$1';
At the end line since wildcard placeholder intercepts other routes.
Like:
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['default_controller'] = 'Sayfa/view';
$route['Sayfa'] = 'Sayfa/view';
$route['Kayit'] = "Kayit/index";
$route['(:any)'] = 'Sayfa/view/$1';// (:any) wildcard catcher must go at the end
Also, you are good to remove trailing slashes from routes.
From docs:
Routes will run in the order they are defined. Higher routes will always take precedence over lower ones.
Related
I have a site that I want to pass directly to the controller method without going through the class in codeigniter.
https://website.com/product_number instead of https://website.com/index/product_number
I want that to go directly to my main controller method.
config/routes.php
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
controllers/Welcome.php
function index($product_number)
{
//process $product_number output
}
Would this be possible in codiegniter?
Open config/routes.php then add this line to it
$route['(.+)'] = 'welcome/index/$1'; I hope this helps your situation.
Open
/application/config/config.php
then find this line
$config['base_url'] = 'https://website.com/index/';
and Replace with
$config['base_url'] = 'https://website.com/';
I hope this Aswer very helpful for you.
I am struggle with URI rerouting in my codeigniter version(2.2.0)application.
Here is my routes.php
$route['details/(:num)'] = 'agent/manage_agents/$1';
And in my view file
foreach($data as $value) {?>
Manage
}?>
But i will get 404 error.
In my Controller file
class Agent extends CI_Controller {
public function manage_agents($id)
{
echo $id;
}
}
UPDATE
Finally i found Which causes the problem.In my routes.php
$route['(:any)'] = "spotmyticket/$1"; when hide this line everything works fine.
Here is my complete routes.php
$route['404_override'] = '';
$route['default_controller'] = "spotmyticket";
$route['ticket']="ticket";
$route['ticket/(:any)'] = $route['ticket'].'/$1';
$route['captcha'] = "captcha";
$route['captcha/(:any)'] = "captcha/$1";
$route['admin'] = "admin";
$route['admin/(:any)'] = "admin/$1";
$route['userdashboard'] = "userdashboard";
$route['userdashboard/(:any)'] = "userdashboard/$1";
$route['fbci'] = "fbci";
$route['fbci/(:any)'] = "fbci/$1";
$route['(:any)'] = "spotmyticket/$1";
$route['agent-management'] = 'agent/index';
$route['register'] = "agent/agent_register";
$route['test'] = 'agent/test';
$route['details/(:any)'] = 'agent/manage_agents/$1';
Please define $route['(:any)'] = "spotmyticket/$1"; as the last rule in routes.php. Everything will be fine. This rule is for any url so all rules defined after this rule will be ignored.
If you are writing this route:
$route['details/(:num)'] = 'agent/manage_agents/$1';
so that you may pass any integer value (like you are passing $value['id']), then try using (:any) instead of (:num). So your route should be:
$route['details/(:any)'] = 'agent/manage_agents/$1';
I got error "Unable to determine what should be displayed. A default route has not been specified in the routing file"
I have two controllers 1.signup and 2.login_control !
How to set routes in routes.php file ? my baseurl is http://localhost:1337/PhpProject1/
my code is below in routes.php file
$route['signup/(:any)'] = 'signup';
$route['login_control/(:any)'] = 'login_control';
$route['404_override'] = '';
First, specified your default route by your first controller.
Like this-
$route['default_controller'] = "signup";
and then add your another controller.
$route['login-control'] = 'login_control';
Do like this
Syntax
$route['how_its_look_like'] = 'controller_name/method';
Example
$route['signup'] = 'login/signup';
$route['login'] = 'login/login';
$route['logout'] = 'login/logout';
$route['404_override'] = '';
Links
Ccodeigniter Routing Examples
I want to route:
site.com/add-your-business to site.com/addyourbusiness
Can you do that with the -
this does not work:
$route['add-your-business'] = "addyourbusiness";
$route['default_controller'] = "home";
$route['404_override'] = '';
I have the controller addyourbusiness set up but getting this page error:
Not Found
The requested URL /add-your-business was not found on this server.
Thanks for any help.
so the thing is I'm using .htaccess to hide the index.php but I still get the controller name in the url like that: http://example.com/name_controller/about
My question is: is it possible to hide the name of the controller, so that only method is shown? hxxp://example.com/name_controller/about
You can define a custom route in config/routes.php - for example:
$route['about'] = 'name_controller/about';
Then, http://example.com/about
goes to http://example.com/name_controller/about
See Hiding the controller’s method name in the URL? in the CI forums for more information.
You can add an entry in the /system/application/config/routes.php file:
$route['about'] = "controller_name/about";
$route['default_controller'] = "xxx";
home
$route['home'] = "xxx/home";
function_name/parameter0/parameter1/parameter2
$route['Collection/(:any)'] = "xxx/Collection/$1";
I did it like this: (config/routes.php)
Code:
$route['((photos|blogs).+)'] = "$1";
$route['([a-zA-Z0-9_-]+)'] = "user/profile/$1";
it is ok correct solutions for common.
You can add below code in the /application/config/routes.php file:
$route['default_controller'] = "Home";
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['(?i)about'] = "Home/about";
$route['(?i)login'] = "Home/Login";
$route['(?i)products'] = "ProductController/ProductList";
$route['(?i)addproduct'] = "ProductController/AddProduct";
$route['(?i)editproduct'] = "ProductController/EditProduct";
$route['(?i)products/(:any)'] = "ProductController/ProductList/$1";//search product list perameters.
100% It work..