MichDe / sweetcron

Automatically exported from code.google.com/p/sweetcron
Other
0 stars 0 forks source link

Placing Sweetcron into a site sub-folder kept giving me a 404 error #21

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Place Sweetcron files into http://<yoursite.com>/sweetcron/
2. Edit the .htaccess file and config.php file as instructed on http://
code.google.com/p/sweetcron/wiki/Installation
3. Now access http://<yoursite.com>/sweetcron/ and you'll see a 404 error 
page.

What version of the product are you using? On what operating system?

I am running PHP 5.2.5 + Apache 2.0 + mod_rewrite enabled.

Original issue reported on code.google.com by little...@gmail.com on 28 Aug 2008 at 7:24

GoogleCodeExporter commented 9 years ago
I've figured it out I think. The problem seems to be that CodeIgniter's URI 
class 
parses the URI - http://<yoursite.com>/sweetcron/ - and returns /sweetcron/ as 
a 
'segment', when it really ought to ignore that bit since it's part of the base 
site 
URL.

So what happens is that in Router::_parse_routes  (system/libraries/Router.php) 
the 
following call gets made:

$this->_set_request($segments);

$segments is an Array([0] => 'sweetcron'). Thus, the 
Router::_validate_request() 
call later on fails since there is no file: system\application\controllers
\sweetcron.php  (or something like that!)

Original comment by little...@gmail.com on 28 Aug 2008 at 7:27

GoogleCodeExporter commented 9 years ago
My quick and dirty fix:

In system/libraries/Router.php find Router::_parse_routes method and replace 
the 
following:

$this->_set_request($this->uri->segments);

with:

// count no. of slashes in base_url_path as n -> disregard (n-1) 
// uri segments
$config = & get_config();
$base_url_parsed_array = parse_url($config['base_url']);
$base_url_path = $base_url_parsed_array['path'];
$numSlashes = substr_count($base_url_path, '/');
$segments =  array_slice($this->uri->segments,$numSlashes-1);

// If we got this far it means we didn't encounter a
// matching route so we'll set the site default route
$this->_set_request($segments);

Original comment by little...@gmail.com on 28 Aug 2008 at 7:29

GoogleCodeExporter commented 9 years ago
Can you attach your revised Router.php? I'm having the same problem hosting it 
in a sub-folder.

Original comment by cineve...@gmail.com on 28 Aug 2008 at 7:52

GoogleCodeExporter commented 9 years ago
I've attached my Router.php.

Original comment by little...@gmail.com on 28 Aug 2008 at 8:19

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, still getting the same 404 error though.

Original comment by cineve...@gmail.com on 28 Aug 2008 at 8:48

GoogleCodeExporter commented 9 years ago
Make sure you've got the configuration and .htaccess setup correctly as 
explained in 
the installation guide (there's an extra bit at the end for subfolder 
installations).

My .htaccess:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /sweetcron/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

My config.php:

$config['base_url'] = "http://<domain.com>/sweetcron/";

Original comment by little...@gmail.com on 28 Aug 2008 at 8:56

GoogleCodeExporter commented 9 years ago
you do not need to hack around in the core.  everything is handled via config 
and .htaccess.

CI recognises the correct order of uri segments as long as you set the correct 
base url and your htaccess is 
correct.

Original comment by yongf...@gmail.com on 29 Aug 2008 at 2:17

GoogleCodeExporter commented 9 years ago
Are my .htaccess and config.php settings above correct? That's what I had when 
I 
first ran it and it didn't work. The 404 error page I got was being generated 
by the 
show_404() method.

Original comment by little...@gmail.com on 29 Aug 2008 at 6:16