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..
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 have base url localhost/new/ for multi language website. When changing language language appears in the url localhost/new/en etc. The problem is when I change a page the language disapears localhost/new/popular_tests, when staying on that page I change the language the url goes back to localhost/new/en. The aim is to add language to the certain page like localhost/new/popular_tests/en etc.
I have in controller:
public function changeLang($lang_code=''){
$this->lang->load('main', $lang_code=='' ? 'english' : $lang_code);
$this->session->set_userdata('language',$lang_code);
redirect(base_url().''.$lang_code);
}
in the config/route.php I have:
$route['default_controller'] = 'home';
$route['(:any)/test'] = 'home/test/$1';
$route['popular_tests'] = 'home/popular_tests';
$route['404_override'] = '';
$route['translate_uri_dashes'] = TRUE;
$route['^(\w{2})/(.*)$'] = '$2';
$route['^(\w{2})$'] = $route['default_controller'];
Great thanks in advance.
That's because you have a routedefined as $route['^en$'] = $route['default_controller']; which means any url ending with en will point to default_controller.
Try Replacing that route with this:
$route['^new/(:any)/en$'] = 'home/$1';
$route['(:any)/new/en$'] = $route['default_controller'];
PS: This is untested version
You should use this one,
$route['(\w{2})/test'] = 'home/test';
$route['(\w{2})/(.+)'] = '$2';
$route['(\w{2})'] = $route['default_controller'];
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
Working on codeigniter project.
Got stuck with routes.
I want to access en/company/login through en/login, so how do I define routes then?
Right now routes code looks like this:
// URI like '/en/about' -> use controller 'about'
$route['^(en|lv)/(.+)$'] = "$2";
// '/en', '/lv' URIs -> use default controller
$route['^(en|lv)$'] = $route['default_controller'];
$route['company/login'] = "login";
tried:
$route['^(en|lv)/company/login'] = "login";
Obviously, Im not getting something.
Can you help please?
Your problem is (i had the same) that this:
$route['^(en|lv)/(.+)$'] = "$2";
overrides your rule for:
$route['^(en|lv)/company/login'] = "login";
Try this:
$route['^(en|lv)\/(company)\/(.+)$'] = "login";
Maybe it should help you to override the first pattern
And if not, edit the first pattern to this:
$route['^(en|lv)\/(?!company).+$'] = "$2";
$route["(en|fr|gr)/(:any)/login"] = "login/index/$1";
--
public function index($company)
{
$language = strtolower($this->uri->rsegments[3]);
if(!in_array($language, ['en', 'fr'])){
// set a default language
// if the route does not provide a valid one
$language = 'en';
}
// Load the language file for the selected language
// for example english, language/en/en_lang.php
$this->lang->load($language, $language);
}
Thank you for your answer, but it seems that I didnt explain that
/company/ is controller and /login/ is "company" function. Your
solution wont work for me. :/
// The $route should contain the uri,
// you seem to have them mixed up.
// $route['uri'] = "controller/method"
$route['(en|lv)/login'] = 'company/login';