Part of the EllisLab Network

Bug Report

CI Fails when bootstrap is not in Web Root in some Setups

Date: 01/07/2008 Severity: Major
Status: Resolved Reporter: section31
Version: 1.5.4
Keywords: Libraries
Forum Thread: http://codeigniter.com/forums/viewthread/48102/P30/#332400

Description

This issue has been discussed before, but it was never resolved (http://codeigniter.com/bug_tracker/bug/default_controller_with_multiple_applications_bug/), so I would like to bring this up again for the next release of CI. 

Problem:  CI returns a 404 when bootstrap is not in Web Root in some Server Setups.

Problem Exists In:
_get_uri_string() method in the Router Library (system/libraries/Router.php).

$_SERVER[’ORIG_PATH_INFO’] on some servers return the entire path of the Web Root along with the bootstrap, yet it is compared to the “/”.SELF

Example:
Code Igniter bootstrap exists in a subdirectory on your website. 
http://mydomain.com/ci/index.php

$_SERVER[’ORIG_PATH_INFO’] returns ‘/ci/index.php’ which is compared to ‘/’.SELF which in turn fails and returns this for Routes.php.  It then uses this string to set the controller and method to find that it does not exist.

As i stated earlier, this is only affected in some server configurations, so that is why some are unable to replicate.  According to the thread, most of the people complaining are on a dreamhost environment, but surely this is not their fault.  It’s just that the $_SERVER[’ORIG_PATH_INFO’] variable is set on dreamhost servers and not in others, so it never short circuits the if statement entirely and instead makes an incorrect comparison in the _get_uri_string(). 

Numerous quick fixes are available on the following thread http://codeigniter.com/forums/viewthread/48102/P30/#332400

However, this should be looked at more carefully by the Rick and Derick to determine how they would like to change the Router Class and if they actually want to add anymore vars in the bootstrap to configure.

Expected Result

Actual Result

Comment on Bug Report

Page 1 of 1 pages
Posted by: Derek Jones on 29 January 2008 11:39pm
Derek Jones's avatar

Playing catchup here; read this, the original bug report, and the thread quoted.  I have a few followup clarification questions, please.

1) So, on your server, ORIG_PATH_INFO has what you expect it to have, except when there is no URI request following the index.php.  Correct?

2) You can get identical behavior without .htaccess and leaving index.php in the URL?

3) What version of PHP are you running?

4) What is your setting for cgi.fix_path_info?

Posted by: section31 on 30 January 2008 2:04pm
section31's avatar

Hi Derek, I appreciate you getting around to fixing this. 

1) Correct, it appears to work when I put a complete uri request.  It only returns an error when I don’t specify a controller in the uri.

2) Yes, same behavior without htaccess and just the index.php in the url.

3) PHP Version 5.2.3

4) 1

Would you like me to setup an ftp and test domain for you on my dreamhost account so you can actually debug in this environment?

Posted by: Derek Jones on 30 January 2008 2:08pm
Derek Jones's avatar

Before doing that, can you try setting cgi.fix_path_info to 0 if you have that option?

Posted by: section31 on 30 January 2008 2:36pm
section31's avatar

OK just finished trying it and nope...still doesn’t work.

Posted by: section31 on 30 January 2008 3:02pm
section31's avatar

Sent you a private message.

Posted by: Derek Jones on 3 February 2008 9:40am
Derek Jones's avatar

I’m not seeing the exact behavior reported, section31, though this certainly is different from my experience with working with ORIG_PATH_INFO.  It would appear on this server that is basically the full REQUEST_URI, e.g.

http://example.com/subfolder/index.php/foo/bar/
ORIG_PATH_INFO = /subfolder/index.php/foo/bar/

It always carries the absolute path to the script in it from what I am seeing, so the solution presented would not work to only compare it to that path when the script is accessed with no URI, but to always replace the SCRIPT_NAME / PHP_SELF with an empty string to remove it from the URI, leaving

/foo/bar/

Please let me know if this is not what you are seeing, and feel free to modify my test script on your server at /opi_test/index.php

Posted by: section31 on 3 February 2008 11:58am
section31's avatar

You’re right, I do believe that would be the simplest solution to fixing this problem.

1) I’m assuming $_SERVER[’SCRIPT_NAME’] is set and acts the same on all servers so we don’t run into another problem in the future?
2) Where do you plan on making the str_replace()?

Posted by: Derek Jones on 3 February 2008 1:30pm
Derek Jones's avatar

1) Best I recall, SCRIPT_NAME is available all the time, and PHP_SELF is available when PHP is run as an Apache module, which would be immaterial if the URI parsing has made it to the ORIG_PATH_INFO check.  A quick double check before committing any code would be done first of course.

2) As this only affects ORIG_PATH_INFO, within that conditional.  Of course, I still need to check with other servers using this method, as again, this is counter to the behavior I’m used to, so while such a str_replace() would not likely affect any URIs that did not contain this information, it may be necessary to be safe to find another common denominator to be able to intelligently distinguish between a server exhibiting one behavior or the other.

Posted by: section31 on 3 February 2008 1:50pm
section31's avatar

I’m glad we are finally on the same page.  Keep me posted.

Posted by: section31 on 4 February 2008 10:09am
section31's avatar

Perhaps the status of this bug should be changed to confirmed smile

Posted by: Derek Jones on 4 February 2008 10:11am
Derek Jones's avatar

No, I’m not ready to rule as to whether this bug is external or not.  I need to check on a few other servers from other hosts that use ORIG_PATH_INFO.

Posted by: section31 on 4 February 2008 10:28am
section31's avatar

http://www.google.com/search?q=php+ORIG_PATH_INFO&hl=en&client=firefox-a&rls=org.mozilla:en-US:official&hs=0A3&pwst=1&start=40&sa=N

I googled and found quite a few php infos (last few results on 1st page) on several servers that use ORIG_PATH_INFO and all of them show the full path.

Posted by: section31 on 6 April 2008 5:49pm
section31's avatar

Did you give up on this derek?

Posted by: Derek Jones on 7 April 2008 9:01am
Derek Jones's avatar

No, though February was totally gobbled by SXSW preparation, and we’ve been very busy since we got back as well.  It’s still my intent to apply an official fix for this prior to the release of version 1.6.2.

Posted by: SurnameJohn on 6 June 2008 11:52am
SurnameJohn's avatar

Dear CI Community, I recently stumbled over this bug für a certain project and red the accorting forum threads:

http://codeigniter.com/forums/viewthread/48101/

http://codeigniter.com/forums/viewthread/46840/ points to:
http://codeigniter.com/forums/viewthread/48102/

I would throw in another solution which works for me (experimental state, not fully tested yet):

I know this is not a clean and sufficient solution, but maybe it support you anyhow.

Feedback appreciated wink

* Precondition: The files of CI resides in the subdir t_dynamic

* .htaccess:
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_URI} !^/t_dynamic/
RewriteRule ^test/(.*)$ /t_dynamic/index.php/urinode/handler/$1 [NC,L]

* system/application/config/config.php:
added following line
$config[’uri_offset’] = “test”;

* system/libraries/URI.php:

added methode to class CI_URI:
function _eliminate_urioffset()
{
$this->uri_string = preg_replace("/^\/”.$this->config->item(’uri_offset’)."/", “”, $this->uri_string );
// If the URI contains only a slash we’ll kill it
if ($this->uri_string == ‘/’)
{
$this->uri_string = ‘’;
}
}

modified methode _fetch_uri_string()

after each assignment of “$this->uri_string = ...” I added: $this->_eliminate_urioffset();

SurnameJohn

Posted by: Derek Jones on 6 June 2008 11:55am
Derek Jones's avatar

Thanks SurnameJohn - this bug report is already resolved.  If you have a new issue, please either start a new forum topic to discuss it, or if you have a confirmed bug, you may post a new bug report to the tracker.  Thank you!

Name:

Email:

Location:

URL:

Remember my personal information

Notify me of follow-up comments?