This is my routes setup code
$route['general/(:any)'] = "videos/filter/$1/1";
$route['general/(:any)/(:num)'] = "videos/filter/$1/1/$2"; //pagination
Following link works fine.
www.example.com/general/latest
But below link doesn't work like what i want
www.example.com/general/latest-trending/5
$route['general/(:any)'] only executes always.
How to solve this issue?
Reverse the order:
$route['general/(:any)/(:num)'] = "videos/filter/$1/1/$2"; //pagination
$route['general/(:any)'] = "videos/filter/$1/1";
You want more specific routes first, because if the shorter one matches first, it will ignore all other routes.
Related
I am using the latest version of CodeIgniter on Server2008 with IIS7.5
I have all of my CI files in a folder mywebsite.com/survey
nps = Controller
survey = Function
client_id = variable base64 encoded client number
I have a script that runs when you visit:
http://mywebsite.com/survey/nps/survey/client_id/MjgzOTcyMW
But I want for it to run when you visit:
http://mywebsite.com/survey/MjgzOTcyMW
How do I set up my routes.php?
I currently have:
$route['/:any'] = 'nps/survey/client_id/';
try
$route['(:any)'] = 'nps/survey/client_id/$1';
or
$route['survey/(:any)'] = 'nps/survey/client_id/$1';
You have to make sure you don't mix up your routes here:
Using just $route['/:any'] would be wrong (even if you had the (:any) correct.
To properly define a route), remember that the left hand side is the pattern route, and the right hand (after the =) is the translated controller/method/parameter format.
So define the route (after all your other routes) as they are to be ordered from MOST specific to least specific (similar to ALLOW/DENY rules etc;):
$route['survey/(:any)'] = 'nps/survey/client_id/$1';
I have a problem with codeigniter and cyrilc url I'm trying to do something like this,
site.com/home
site.com/начало
in my router I've got
$route['([А-Яа-яa-zA-Z0-9-]+)'] = "home/index/$1";
Which dosn't work I put in my config.php and
$config['permitted_uri_chars'] = 'a-zа-яё 0-9~%.:_\-';
but still dosn't work then I found in internet
$route['(:any+)(?:(.html))?'] = "home/page/$1";
Which is working but, now I lose my router native behavior because :any gives and /
so Is there a way to use (:any) but not actually any, so I can keep my router behavior
Thank you in advance
I want to create location pages in my codeigniter site. So I have one contrller named locations and index method. So all the requests http://mysite.com/location_name should be landed to http://mysite.com/index.php/locations/index. And all other should work as it is like http://mysite.com/login should be landed to http://mysite.com/index.php/home/login. Contact us http://mysite.com/contact-us should be landed to http://mysite.com/index.php/home/contact.
I tried to achieve this by writing following line route rule (route.php):
$route['(:any)'] = 'locations'; //location name can be anything around the world
So locations are working fine, but http://mysite.com/login and http://mysite.com/contact-us are not working, they redirecting continuously in infinite loop.
Please suggest the solution. Thank.
The routes are applied from top to bottom, so you need to have your more specific rules listed first, then your more generic rules last:
$route['login'] = 'home/login';
$route['contact-us'] = 'home/contact';
$route['(:any)'] = 'location/index';
I see that you mentioned you've tried changing the order of rules in your route file. So If you have done this and it's not working - you have something else going on.
I would check these things:
.htaccess file (if you're using it)
controllers that are causing the infinite loop (any redirections in there, _remap method, etc. )
I want to group my controllers, views and models into public/ and members/ subfolders.
But for the public stuff, I don't want /public/ to show in the URL, so:
http://mysite.com/ & http://mysite.com/section/
should point to: /public/home & public/section/
How should I change routes.php to accommodate this?
(I'm fine with members/ stuff having members/ in the url)
To make http://mysite.com/ point to /public/home you will need to mark public/home as your default controller. You will also need to add a specific route to make http://mysite.com/section point to /public/section. Try this (the regex is a little dubious in my opinion, but may do what you want):
$route['default_controller'] = "public/home";
$route['section/(.*?)'] = "public/section/$1";
Kindly see if this works for you:
$route['section'] = "public/section";
Your index page would remain as "public/index.php"
You don't need to add routes for every controller.
This works for me:
$route['members'] = 'members'; // route members to members
$route['members/(.*?)'] = 'members/$1'; // route members/... to members/...
$route['(.*?)'] = 'public/$1'; // route anything but above lines to public/...
The first two lines are intentionally redundant to protect 'members' segment from being routed to 'public'. And the third line does the magic.
I am trying to work out the code igniter routing
I have a url that will look like
http://example.com/register
I want that to hit
http://example.com/account/register/normal
I also have
http://example.com/invite/something_random_here
which I want to hit
http://example.com/account/register/invite/something_random_here
I also have
http://example.com/register/something_random_here
which I want to hit
http://example.com/account/register/subscribed/something_random_here
How do I setup these routes?
Pretty much Straight out of the User Guide
$route['register'] = "account/register/normal";
$route['invite/(:any)'] = "account/register/invite/$1";
Basically anything after invite/ will get tacked onto the end of account/register/invite. I believe it only works for one segment, if you want multiple segment support you'll have to use a regular expression:
$route['invite/(.+)'] = "account/register/invite/$1";
Another usefull one (because I believe (:any) only works for characters) would be:
$route['invite/([a-zA-Z0-9_-]+)'] = "account/register/invite/$1";
This will let all alpha-numeric values (single segment) with _ or - go through, great for GUIDs :)
I believe for your first URL, you would use the following route:
$route['register'] = "account/register/normal";
Your second URL, would make use of the following route:
$route['invite/(:any)'] = "account/register/invite/$1";
Both of these routes would need to be placed in your "config/routes.php" file.
Hope this helps?