Strange (to me) routing behaviour |
Hi All,
I was hoping to get some clarification about routing. I was under the impression that the only pages you could access were ones that were setup in the routes.php file. Example: URL: abc.com Route entry: $route['hello'] = 'example/hi'; As expected, I can access the page at abc.com/hello. Now, if i comment out that line in the code: //$route['hello'] = 'example/hi'; I get a 404 if i try accessing abc.com/hello (which again, I expect). What I find peculiar though is that if I enter abc.com/example/hi in my browser, I can access the content. I didn't know that such a thing was possible. Could someone offer me some insight (even if it's just as simple as yes... it is possible)? Not sure if it makes a difference but here is my .htaccess file: RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L] Thanks.
try this
Code: <IfModule mod_rewrite.c>
www.arthnugraha.com
Learning by doing
There's nothing wrong with your .htaccess file, it's your assumption about how routing in CodeIgniter works was wrong ... I don't know where you got that from, it's all explained in the manual:
https://ellislab.com/codeigniter/user-gu...uting.html
(12-04-2014, 09:22 PM)lazylazz Wrote: I get a 404 if i try accessing abc.com/hello (which again, I expect). What I find peculiar though is that if I enter abc.com/example/hi in my browser, I can access the content. I didn't know that such a thing was possible. Could someone offer me some insight (even if it's just as simple as yes... it is possible)? /hello is not an actual controller, so your route setting told it to use example/hi (controller/method) Codeigniter by default however will look for a controller with same name /example/hi codeigniter will go to your example controller and run your hi method because it exists. (Some frameworks require you set all the routes, Codeigniter will auto match to controller files by name. )
Ok, the good and the bad (for me anyway)
1) the CI ".htaccess" script in the user guide does in NO WAY shape or form work (with MY setup) I have win8.1, wamp 2.5 To start, Followed tutorial. ALWAYS copy and pasted to avoid typo's. Tutorial works fine except for "view article" links but still have one more page to go..maybe the fix is on that page? Ran <?php phpinfo(); ?> to verify that removing the # from the mod_rewrite Loadmodule was successful. Apache set to www so that's good What wamp does - Opens localhost as usual with default page. Click on project...reopens default page (w/o wamp icon) Keep clicking - same result. Use modified .htaccess from above post. Functionality restored WTF? BUUUT...still have to use index.php/news or whatever. Would anyone like to enlighten me on why the *bleep* I just put myself thru all of that for absolutely NO result???? This is why I threw the towel in on Cake. I swear to F'ing christ if I can just get rid of the index.php I will NEVER in my *bleeping* life EVER....EVER screw with mod_rewrite again. You have my word on it! Sorry for frustration but, I've googled the crap out of it and nothing. I just can't win with mvc frameworks, perhaps I should just hard code a minimalist backend to get the mysql functionality I desire since I can't find it anywhere else ![]() This learning experiment has not been fun....
Try this one, it's the one I use and always has worked for me.
PHP Code: <IfModule mod_rewrite.c> What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |