I have the following URL:
http://test.com/news
Where http://test.com/ is a base URL.
news is controller.
For this URL there is route:
$route['news'] = "news/index";
I need that to work this URL:
http://test.com/en/news
For this I tried routing rule:
$route['(\S{2})/news'] = "news/index";
$route['(^\S+)/news'] = "news/index";
$route['^(\S+)/news'] = "news/index";
But It does not work
Unless there is a specific reason you are using regular expressions that I am unaware of, you can accomplish what you are after with the following route:
$route['(:any)/news'] = "news/index";
Related
I have created a multi-language website.
Facing issue while creating SEO user-friendly URL.
current URL:
http://localhost/example/en/user/myaccount OR
http://localhost/example/fr/user/myaccount
want to change it with
http://localhost/example/en/myaccount OR
http://localhost/example/fr/user/myaccount
routes.php
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
// URI like '/en/about' -> use controller 'about'
$route['^(en|de|fr|nl|id|es)/(.+)$'] = "$2";
// '/en', '/de', '/fr','/es' and '/nl' URIs -> use default controller
$route['^(en|de|fr|nl|id|es)$'] = $route['default_controller'];
also tried with
$route["myaccount"] = "user/myaccount";
$route["^(en|de|fr|nl|id|es)$/myaccount"] = "user/myaccount";
Nothing will work in this case. Already used following in routes.php file other demo projects with out multi-language. There it's work perfectly.
$route["myaccount"] = "user/myaccount";
Thanks in advance
you can consult the documentation for routes here
https://www.codeigniter.com/user_guide/general/routing.html
and for your problem
$route["(:any)/myaccount"] = "user/myaccount/$1";
I want to use a segment base URL and a query string URL with CodeIgniter at the same time, and in the same project, for example http://localhost/finance_new/login/logout and http://[::1]/finance_new/?c=login&m=logout.
When I set enable_query_string to true, it only works for the second pattern but not for the first.
How can I use both URLs?
I am using CodeIgniter version 3.0.
You probably forget to set base_url() in application/config/config.php.
Just set base_url() like this..
$config['base_url'] = 'http://localhost/finance_new/';
Then
$config['enable_query_strings'] = TRUE;
When using
$route['(:any)'] = 'pages/view/$1';
and I want to use other controllers in my routing for example:
$route['del/(:any)'] = 'crud/del';
it won't work. I guess it will use
pages/view/del/$1
and not my crud-controller when deleting an item. How can I solve this?
As indicated, $route['(:any)'] will match any URL, so place your other custom routes before the "catch-all" route:
$route['del/(:any)'] = 'crud/del';
// Other routes as needed...
$route['(:any)'] = 'pages/view/$1';
Its hundred percent working
$route['(:any)'] url is placed last in your routes file
$route['(:any)/company_product_deal_detail'] = "mypage_product_picture/deal_detail/$1";
$route['(:any)/company_service_deals/(:any)'] = "mypage_service_deal_list/index/$1";
$route['(:any)/company_service_deals'] = "mypage_service_deal_list/index/$1";
$route['(:any)'] = "company/index/$1";
I know that it's an old question, but I have found myself a nice solution.
By default, CodeIgniter gives priority to URL's from routes config (even if straight controller, method etc. specified), so I have reversed this priority this way:
In system/core/Router.php find _parse_routes method.
Add this code under literal route match:
$cont_segments = $this->_validate_request($this->uri->segments);
if ($cont_segments == $this->uri->segments) {
return $this->_set_request($cont_segments);
}
I agree, that this approach is kinda wrong, because we edit file from system/core, but I needed a fast soluttion to work with a lot of URL's.
I have my route collection and want to retrieve the url pattern (defined in global.asax) of a given route.
In application:
var route = RouteTable.Routes["UserIndex"];
Global.asax:
routes.MapRoute(
name: "UserIndex",
url: "u/{userId}"
In the web application I am not able to access the Url Pattern (in the route object) which were defined in global.asax. Is there another way?
Im asking this because I need to define some route patterns to be used with Knockout.js in template list.
Try something like:
Route userRoute = RouteTable.Routes[UserIndex"] as Route;
string pattern = userRoute.Url;
$route['ajax/get/mail'] = "mail/get_mail_by_params";
I am trying to request *ajax/get/mail?user_id=123&foo=bar&bar=foo*
And params it in controller:
$foo = $this->input->get('foo')
But $_GET in ajax/get/mail variable is empty!
I suggest, that routing doesn’t supports GET paramets. What to do?
Have you tried using the MY_Input library? http://codeigniter.com/wiki/MY_Input/
Also, I think you may need to update your URI Protocol in config.php to PATH_INFO.
$config['uri_protocol'] = "PATH_INFO";