CodeIgniter Forums
Routing oddity - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Routing oddity (/showthread.php?tid=28091)

Pages: 1 2


Routing oddity - El Forum - 03-01-2010

[eluser]Jeffrey McManus[/eluser]
Hi all,

Just ran across something pretty weird in my CI 1.7.2 app. I'm using .htaccess to get rid of index.php and my index_page is set to an empty string in config.php the way it's supposed to be.

I create a controller like this (in a file called content.php), and it works fine:

Code:
<?php
class Content extends Controller {

    function test() {
        echo "Test!";
    }
}
?>

But if I create a nearly identical controller in a file called stories.php, it doesn't work. The file stories.php has this code:

Code:
<?php
class Stories extends Controller {
    
    function test() {
        echo "Test!";
    }
}
?>

Navigating to http://localhost/myapp/content/test/ works, but http://localhost/myapp/stories/test/ does not; it returns the error "The requested URL /myapp/stories/test/ was not found on this server.".

This is sort of mind-boggling, what could be the problem?

TIA...


Routing oddity - El Forum - 03-01-2010

[eluser]danmontgomery[/eluser]
Are you on a windows machine or linux based? Files should be capitalized (Content.php, Stories.php), which makes a difference on ext systems but not windows... Works fine on my local machine exactly as you've described, what if you remove .htaccess?


Routing oddity - El Forum - 03-01-2010

[eluser]Jeffrey McManus[/eluser]
I'm on OSX.

In the previous example I gave, "content.php" was not capitalized and it worked OK, but stories.php did not. I did rename the file to Stories.php though just to rule that possibility out -- no luck.

Removing the .htaccess completely causes all requests for pages other than the home page to fail, as expected.

My .htaccess is this:

Code:
Options -Indexes
Options +FollowSymLinks
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /myapp/
    RewriteCond %{REQUEST_FILENAME} !index.php
    RewriteRule (.*)\.php$ index.php/$1
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

I can navigate to my site's home page at http://localhost/myapp/.


Routing oddity - El Forum - 03-01-2010

[eluser]Jeffrey McManus[/eluser]
It's probably also worth noting that navigating to http://localhost/myapp/index.php/stories/test will work in this configuration (although that's not what I expected and it's not what I want -- my expectation is that I can use http://localhost/myapp/stories/test and view the output from the test() member of the Stories controller.


Routing oddity - El Forum - 03-01-2010

[eluser]Twisted1919[/eluser]
Code:
The requested URL /myapp/stories/test/ was not found on this server.
This is APACHE error NOT CI . So you are doing something wrong with your htaccess .


Routing oddity - El Forum - 03-01-2010

[eluser]Jeffrey McManus[/eluser]
Well, yes, that's why I posted it.

But it's a little weird, don't you think, that it's working OK for one controller and not for another controller, when the only difference is the file name (and corresponding controller class name)?

Unless I'm missing something there's nothing in the .htaccess I posted that would treat a controller named "stories.php" differently than "content.php"? Right?


Routing oddity - El Forum - 03-01-2010

[eluser]Twisted1919[/eluser]
maybe content.php is your default route/controller ?


Routing oddity - El Forum - 03-01-2010

[eluser]Jeffrey McManus[/eluser]
I don't think that's it. In my routes.php, the value of $route['default_controller'] is 'home' and that works correctly.

All of my other controllers work correctly too (I can go to http://localhost/myapp/content/test and that works as I'd expect).


Routing oddity - El Forum - 03-01-2010

[eluser]Twisted1919[/eluser]
Have you tried and play with $config['uri_protocol'] ?
Go with that and tell us what's the answer , maybe that's the reason (?) .


Routing oddity - El Forum - 03-01-2010

[eluser]Jeffrey McManus[/eluser]
I tried every combination, here's what happened:

$config['uri_protocol'] = "AUTO";
http://localhost/myapp/index.php/stories/test/
WORKS

$config['uri_protocol'] = "AUTO";
http://localhost/myapp/stories/test/
FAILS

$config['uri_protocol'] = "PATH_INFO";
http://localhost/myapp/stories/test/
FAILS

$config['uri_protocol'] = "QUERY_STRING";
http://localhost/myapp/stories/test/
FAILS

$config['uri_protocol'] = "REQUEST_URI";
http://localhost/myapp/stories/test/
FAILS

$config['uri_protocol'] = "ORIG_PATH_INFO";
http://localhost/myapp/stories/test/
FAILS