I want to route so that the "domain" part dissapears,
http://www.domaininfo.za/domain/google.com
to something like this
http://www.domaininfo.za/google.com
I have managed to remove the welcome part but how do i remove domain?
my route file:
$route['default_controller'] = "welcome";
$route['404_override'] = '/';
$route['(:any)'] = "welcome/domain/$1";
Not sure if this is what you're asking, but does this work for you?
$route['(:any)'] = "domain/$1";
Your routing is dangerous...I would put a regex in the route key to recognize web domains, then route it to welcome/domain/$1. Right now you are routing all values in the controller space to welcome/domain/$1. Mod-rewrite or using regex in your router would be best.
Related
I want to maintain a complex URL structure while routing. I could not write routing for the following requirement.
If the URL comes with http://localhost/api/cals/func/id I want to route it to http://localhost/api/cals/func/id, otherwise I want to route the URL to http://localhost/home/.
I tried this but it is not working in all use cases.
$route['api/(:any)'] = 'api/(:any)';
$route['(:any)'] = 'home/index/';
Why is this so?
This may help you;
You must use $1 for it.
$route['default_controller'] = 'home/index/';
$route['api/(:any)'] = 'api/$1';
$route['(:any)'] = 'home/index/';
So I've got a mostly static site. My default controller handles most views in it's index action, simply passing the $this->uri->segment(1) through to my template.
$route['default_controller'] = 'master';
$route['(:any)'] = 'master';
$route['404_override'] = '';
But now I'm implementing a new controller that I would like to have default behavior. And I don't want to be sullying up my routes config with superfluous routes for every single action. So how can I say, route anything to the default master controller except for NewController, which you should handle normally.
Use the 404_override route location to handle your wildcard pages. That way you won't need to define every existing controller/method that you create.
Just make sure that the 404_override controller/method then correctly outputs an HTTP 404 header, and any appropriate output for the browser.
Not totally sure what you mean but if I understand you correctly if you add the line
$route['NewController'] = 'NewController';
In before the (:any) route it should load it first.
$route['default_controller'] = 'master';
$route['NewController'] = 'NewController';
$route['(:any)'] = 'master';
$route['404_override'] = '';
I have two controllers
1- site
2- management
the first controllers(Site) is work successfuly
the second controllers(Managemnt) is not work.
I don't know what is the errror
I change the routes.php but still doesn't work(managment)
$route['default_controller'] = "site";
$route['(:any)'] = "site/$1";
$route['Administration'] = "Administration/index";
$route['Administration/([a-z])'] = 'Administration/$1';
this links work:
example.com/hotel/12312
example.com/contact
example.com/city/newyork
example.com/Administration
but this links doesn't works:
example.com/Administration/hotels
example.com/Administration/add_new
example.com/Administration/cities
where is the problem pls because I tired to solve this problem
thaks
It has to do with the order in witch you are giving route directives.
Code igniter routes requests from top to bottom, so if you want your $route['Administration'] to precede $route['(:any)'] you have to set it first.
$route['default_controller'] = "site";
$route['Administration/([a-z])'] = 'Administration/$1';
$route['Administration'] = "Administration/index";
$route['(:any)'] = "site/$1";
I would allways sugest putting (:any) routes at the end so they don't overwrite more specific routes.
I had same problem & I get this working:
$route['default_controller'] = "welcome";
$route['([a-z-A-Z1-9_]+)'] = "site";
$route['management']="management";
$route['404_override'] = '';
it may help you!
I'm not familiar with Codeigniter routing, but to me looks like everything is matching $route['(:any)'] = "site/$1"; before it ever reaches your Administration routes. Try moving it below everything else...you might also have to switch your Administration routes for the ([a-z]) to match
$route['default_controller'] = "site";
$route['Administration/([a-z])'] = 'Administration/$1';
$route['Administration'] = "Administration/index";
$route['(:any)'] = "site/$1";
I have defined a new route on routes.php but it have problem.
$route['default_controller'] = "index";
$route['404_override'] = '';
$route['(:any)'] = "oyna/oyun/$1";
I want to redirect /2012.htm to oyna/oyun/2012.htm and I can but it create a new problem. I can't reach my other controller if I don't define as below:
$route['default_controller'] = "index";
$route['404_override'] = '';
$route['admin/(:any)/(:any)'] = 'admin/$1/$2';
$route['admin/(:any)'] = 'admin/$1';
$route['kategori/(:any)'] = "oyna/kategori/$1";
$route['(:any)'] = "oyna/oyun/$1";
If i don't define any controllers on routes.php like above I can't reach that.
What i need to do for solve?
I'm not sure, but try to replace $route['(:any)'] = "oyna/oyun/$1"; with $route['(:num).htm'] = "oyna/oyun/$1.htm";
Or better: $route['(\d+).htm'] = "oyna/oyun/$1.htm";
CodeIgniter's routes are a little funny, but once you understand how they're processed, it makes perfect sense.
Since routes use regular expression matching, you can't just have something super generic and expect everything else to work, because it's going to look at routes before simply routing to the controller/method implied by the URL.
If you want to match URLs such as http://domain.tld/2njkf4r AND http://domain.tld/pages/about then you will have to create more specific rules to handle "exceptions" to the very general rule that will match the first case.
You are correct that it won't work unless you define the other routes, because with only $route['(:any)'] as a route, EVERY request will match that. That route has to be your absolute last route. It's a pain in the ass, but necessary, because of the way they process routes.
My all links have .htm at end's. And this is the solve:
$route['(:any).htm'] = "oyna/oyun/$1";
Because my controllers haven't got .htm at the end.
I am working on a codeigniter app and am having some trouble wrapping my head around a routing issue. Basically I would like all routes to map to an specific controller action by default, but I would also like to able to specify an array of routes (or ideally initial url segments) which shouldn't follow this pattern.
By way of example:
If I enter domain.com/username it maps to domain.com/controller/method/show/username
If I enter domain.com/account it maps to domain.com/account
Any help very gratefully received!
James
Open config/routes.php and add the following:
$route['(:any)'] = "controller/method/show/$1";
Please see the link below for more routing concepts.
http://codeigniter.com/user_guide/general/routing.html
Routes will run in the order they are defined. So in your routes file, put the routes for other controllers you still want to work above your catch-all for usernames:
$route['default_controller'] = 'home'; //so root url still works
$route['accounts'] = "accounts";
$route['accounts/(:any)'] = "accounts/$1";
...
$route['(:any)'] = "controller/method/show/$1";