Welcome Guest, Not a member yet? Register   Sign In
Pulling my hair out - 404 Not Found
#1

I'm running CI on a lamp install on ubuntu 14.04

At the risk of boring everyone to death .... I got a problem with 404 Not Found when trying to redirect.

Here's my controller:
<code>
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Calendar extends CI_Controller
{


public function index($year = null, $month=null)
{
if (!$this->ion_auth->logged_in())
{
redirect(base_url() . 'auth/login', 'refresh');
}


$data=array();
# If first time through then year will be null so set to current to get relevant events.
if ($year ==NULL)
{
$year = date("Y"); // 2011
$month = date("m"); // 01 through 12
}

$data['calendar'] = $this->M_calendar->generate_calendar($year, $month, $data);
$this->load->view('v_calendar', $data);
}

public function testing()
{
$this->load->view('welcome_message');
}


}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */
...

here's my .htaccess

<IfModule mod_rewrite.c>

   # Make sure directory listing is disabled
   Options +FollowSymLinks -Indexes
   RewriteEngine on

   # NOTICE: If you get a 404 play with combinations of the following commented out lines
   AllowOverride All
   RewriteBase /var/www/html
   #RewriteBase /

   # Send request via index.php (again, not if its a real file or folder)
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d

   RewriteCond $1 ^(robots\.txt|favicon\.ico|style\.css)

   # deal with php5-cgi first
   <IfModule mod_fcgid.c>
       RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
   </IfModule>

   <IfModule !mod_fcgid.c>

       # for normal Apache installations
       <IfModule mod_php5.c>
           RewriteRule ^(.*)$ index.php/$1 [QSA,L]
       </IfModule>

       # for Apache FCGI installations
       <IfModule !mod_php5.c>
           RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
       </IfModule>

   </IfModule>

</IfModule>

What, oh what am I doing wrong ...
</code>
Reply
#2

Is the file named Calendar.php? Or Welcome.php? Where and how did you load the M_calendar model?
Reply
#3

It could be a problem with your redirect URL. If you haven't removed index.php from the URL then base_url() would give you the wrong URL. Try replacing this line:

Code:
redirect(base_url() . 'auth/login', 'refresh');

With:

Code:
redirect(site_url() . 'auth/login', 'refresh');
Reply
#4

(02-03-2015, 02:26 PM)Avenirer Wrote: Is the file named Calendar.php? Or Welcome.php? Where and how did you load the M_calendar model?
The controller I'm trying to redirect to is called auth.php and it exists in the controller folder.

The model is autoloaded.


(02-03-2015, 08:10 PM)kilishan Wrote: It could be a problem with your redirect URL. If you haven't removed index.php from the URL then base_url() would give you the wrong URL. Try replacing this line:


Code:
redirect(base_url() . 'auth/login', 'refresh');

With:



Code:
redirect(site_url() . 'auth/login', 'refresh');

I've tried changing base_url to site_url and get the same problem.

Also, I've tried changing the redirect code to

Code:
redirect(base_url() . 'calendar/testing', 'refresh');
which is a method in the same controller and I get the same error.
Reply
#5

Hey blackbulldog,

Are you sure your RewriteBase is correct? Can you tell more about your CI installation like the path you installed CI and the path where the index.php and .htaccess file are.

Correct me if I'm wrong, but when assuming CI is installed in /var/www/html and the index.php and .htaccess are in the same folder, your config should be something like this:

Code:
...
RewriteBase /html/
...
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /html/index.php?/$1 [L]
...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /html/index.php?$1 [L]
...

RewriteBase / is your www folder. That means that you shouldn't use the full path (/var/www/..) as base to your CI installation. 

Hope this helps.

-RogerMore
Reply
#6

(02-04-2015, 02:21 AM)RogerMore Wrote: Hey blackbulldog,

Are you sure your RewriteBase is correct? Can you tell more about your CI installation like the path you installed CI and the path where the index.php and .htaccess file are.

Correct me if I'm wrong, but when assuming CI is installed in /var/www/html and the index.php and .htaccess are in the same folder, your config should be something like this:



Code:
...
RewriteBase /html/
...
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /html/index.php?/$1 [L]
...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /html/index.php?$1 [L]
...

RewriteBase / is your www folder. That means that you shouldn't use the full path (/var/www/..) as base to your CI installation. 

Hope this helps.

-RogerMore

My folder setup is like this:

..[www]
....[html]
........[ci]
..........[application]
..........[system]
..........index.php
..........htaccess

I tried the changes you suggested but still no good...
Reply
#7

If you have your CI installation in it's own ci folder, which is in the folder html, try the following:

Code:
...
RewriteBase /html/ci/
...
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /html/ci/index.php?/$1 [L]
...
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /html/ci/index.php?$1 [L]
...
-RogerMore
Reply
#8

Oh and don't forget to change your config accordingly:
Code:
$config['base_url']    = 'https://www.yourdomain.com/html/ci/';

$config['index_page'] = '';

-RogerMore
Reply
#9

(02-04-2015, 04:33 AM)RogerMore Wrote: Oh and don't forget to change your config accordingly:

Code:
$config['base_url'] = 'https://www.yourdomain.com/html/ci/';

$config['index_page'] = '';

-RogerMore

Thanks, but still no good ...

I changed to htaccess to the settings you suggested and changed

Code:
$config['base_url'] = 'http://localhost/html/ci/';

$config['index_page'] = '';

Now, when I type

localhost/html/ci in my browser I get 404 .... but,

to try to simplify things I commented out the redirect code in my controller but still got the 404 error

but, when I type

localhost/ci

in my browser (with the redirect still commented out) I get shown the view I would expect to see i.e. not a 404

however, when I type

http://localhost/ci/calendar/testing

in my browser (and expect to see the welcome_message view) I get a 404

very confused Confused
Reply
#10

Can I assume that if you get the Welcome view when surfing to localhost/ci, that your web root is /html?

If that's the case you should try to delete the /html in the .htaccess file and in the base_url in the config.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB