Weird routing behaviour |
[eluser]mmackay[/eluser]
It's been one of those weeks and this has been bugging me for a couple of days now. I could just be having a bad week and not spotting the obvious but my routing isn't working as intended. It worked perfectly on v.1.7.3 but when I upgraded to 2.0 it kinda went wrong. Here's the low down... This is my .htaccess file: Code: RewriteRule ^([a-z0-9]+)/audio/([a-z0-9\-]+)(/?)$ index.php/$1/tracks/$2 [L,NC] The idea being that I'm capturing the following URLs: http://www.domain.com/username/audio/audio-item-token <-- Displays the users audio http://www.domain.com/username/video/video-item-token <-- Displays the users videos http://www.domain.com/username <-- Displays all the users items My CI routing file is as follows: Code: $route['(:any)/tracks/(:any)'] = 'user/tracks'; The main $route['(:any)'] = 'user/index'; actually sits at the bottom of the routes file. I'm then using the uri_segment (temporarily) to retrieve the username, validate etc. etc. However, this just simply doesn't work. I'm getting a CI 404 returned for any URL. Strangely though, it works for the users admin URL: Code: RewriteRule ^([a-z0-9]+)/admin(/?)$ index.php/$1/admin [L,NC] Code: $route['(:any)/admin'] = 'admin'; The admin rules appear below the other routes. I don't get how the admin rules work but the main site ones don't? A quick view of the log (when calling http://www.domain.com/mikemackay for example) shows as: DEBUG - 2011-02-11 11:40:43 --> Config Class Initialized DEBUG - 2011-02-11 11:40:43 --> Hooks Class Initialized DEBUG - 2011-02-11 11:40:43 --> Utf8 Class Initialized DEBUG - 2011-02-11 11:40:43 --> UTF-8 Support Enabled DEBUG - 2011-02-11 11:40:43 --> URI Class Initialized DEBUG - 2011-02-11 11:40:43 --> Router Class Initialized ERROR - 2011-02-11 11:40:43 --> 404 Page Not Found --> mikemackay I'm stumped. Anyone got any ideas? Can you spot something simple that I'm overlooking? - Mike
[eluser]InsiteFX[/eluser]
The (:any) should be at the end of your routes. Code: $route['(admin/(:any)'] = 'admin'; InsiteFX
[eluser]mmackay[/eluser]
[quote author="InsiteFX" date="1297446735"]The (:any) should be at the end of your routes. Code: $route['(admin/(:any)'] = 'admin'; InsiteFX[/quote] That doesn't make any difference, if I set the main user up with: Code: RewriteRule ^([a-z0-9]+)/audio/([a-z0-9\-]+)(/?)$ index.php/user/audio/$2 [L,NC] Code: $route['user/audio/(:any)'] = 'user/audio'; It still gives me a 404 if I call the following: http://domain.com/mikemackay/audio/some-...file-token
[eluser]mmackay[/eluser]
Everything now seems to be working, I've updated my .htaccess and routes code as follows: Code: RewriteRule ^([a-z0-9\-]{1,16})(/?)$ index.php/$1/user [L,NC] Code: $route['(:any)/user'] = 'user/index'; I'm pretty sure it's an oversight on my part along the way somewhere. Things started to work around the time I placed the character length limit on the .htaccess regex - although I don't know if this was the exact fix. Thanks for reading and thanks to InsiteFX for the reply. - Mike |
Welcome Guest, Not a member yet? Register Sign In |