Jump to content


Photo

Codeigniter, 404 page not found

codeigniter

Best Answer TFT2012, 20 September 2013 - 04:24 PM

Figured it out.

 

Since the CI will get $uri = $_SERVER['REQUEST_URI'] at the begining even doing the setup $config['uri_protocol'] = 'AUTO'; in config.php.

Using the link through Squid, the $uri will return full http path, like http://mysite:9000/... However, using the link without passing Squid will just return "/index.php/....". The later is recoginzed by CI correctly, but the 1st is not.

So I go to system/core/URI.php, add the following to take of the "http://" part, just make its format same as "/index.php/...."

private function _detect_uri()
	{
		if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME']))
		{
			return '';
		}

		$uri = $_SERVER['REQUEST_URI'];
                // Starts here
		if(strstr($uri, 'http'))
		{
			$temp_uri = explode(':', $uri);
			$uri 	  = str_replace($_SERVER['SERVER_PORT'], '', $temp_uri[2]);
		}
		// Ends here
		if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
		{
			$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
		}

................
................
}
Go to the full post


  • Please log in to reply
1 reply to this topic

#1 TFT2012

TFT2012

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • LocationSouthern California

Posted 20 September 2013 - 11:03 AM

I have setup the CI app at the port 9001. I didn't do the rewrite things. So my url looks like the original one mysite:9001/index.php/category/shoes. It works well before I setup the Squid.

I tried to setup the Squid on the same server with Apache. I assigned the port 9000 to Squid.

To test, I added a simple sysinfo.php file to display phpinfo on the root of my app.

 

It works if I do mysite:9000/sysinfo.php (go through Squid).

However if I do mysite:9000/index.php/category/shoes, it will say "404 page not found". The mysite:9001/index.php/category/shoes still works though.

 

Can anyone give me a hand on this? Thanks!


Edited by TFT2012, 20 September 2013 - 11:05 AM.


#2 TFT2012

TFT2012

    Advanced Member

  • Members
  • PipPipPip
  • 33 posts
  • LocationSouthern California

Posted 20 September 2013 - 04:24 PM   Best Answer

Figured it out.

 

Since the CI will get $uri = $_SERVER['REQUEST_URI'] at the begining even doing the setup $config['uri_protocol'] = 'AUTO'; in config.php.

Using the link through Squid, the $uri will return full http path, like http://mysite:9000/... However, using the link without passing Squid will just return "/index.php/....". The later is recoginzed by CI correctly, but the 1st is not.

So I go to system/core/URI.php, add the following to take of the "http://" part, just make its format same as "/index.php/...."

private function _detect_uri()
	{
		if ( ! isset($_SERVER['REQUEST_URI']) OR ! isset($_SERVER['SCRIPT_NAME']))
		{
			return '';
		}

		$uri = $_SERVER['REQUEST_URI'];
                // Starts here
		if(strstr($uri, 'http'))
		{
			$temp_uri = explode(':', $uri);
			$uri 	  = str_replace($_SERVER['SERVER_PORT'], '', $temp_uri[2]);
		}
		// Ends here
		if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
		{
			$uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
		}

................
................
}





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com