2

In my new CI project, I am getting the following error every time I try to access any URL other than the base url and the base url /index.php. For example, if I'd like to access the "about" page:

Not Found

The requested URL /my_base_url/about was not found on this server.

This is what my routes.php file looks like:

$route['default_controller'] = "base";
$route['about'] = "base/about";
$route['404_override'] = '';

I've triple checked my Base controller and it definitely has an about method (which loads an existing "about" view).

Here's my .htaccess file:

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

And here's a few things I've set in my config.php file:

$config['base_url'] = 'http://localhost/my_base_url/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

What am I doing wrong? Any help much appreciated!

Community
  • 1
  • 1
anniebabannie
  • 139
  • 2
  • 4
  • 9

2 Answers2

1

The htaccess file should be in the my_base_url directory, and you should include a rewrite base:

Options FollowSymLinks

RewriteEngine on
RewriteBase /my_base_url/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I tried this, but then got "Forbidden You don't have permission to access /my_base_url/ on this server." (I checked the permissions on that directory though, and I should be able to view it!) – anniebabannie Oct 14 '13 at 18:50
  • @anniebabannie Are you sure `index.php` is one of the files in the `DirectoryIndex` list? Are you sure the htaccess file is actually getting read (and you have mod_rewrite loaded)? – Jon Lin Oct 14 '13 at 18:52
  • I checked my httpd.conf file and yes, index.php is listed. I tested to see if the htaccess file was getting read by putting in gibberish (resulted in Internal Server Error – so yes it IS being read), and yes mod_rewrite is being loaded. – anniebabannie Oct 14 '13 at 19:13
  • @anniebabannie try checking your error logs, it should give you a reason why it returned a 403 Forbidden (either can't access, or configuration disallows, etc.) – Jon Lin Oct 14 '13 at 19:16
  • I found this "[Mon Oct 14 12:22:54 2013] [error] [client ::1] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden" – I am not used to debugging apache server errors, where should I look to fix this? – anniebabannie Oct 14 '13 at 19:25
  • @anniebabannie means you need to turn on follow symlinks, see the edit above – Jon Lin Oct 14 '13 at 19:29
  • UPDATE: I went to my user .conf file, and added FollowSymLinks to Options, which seemed to work! I can now view my base url page again. Only problem is now my styles aren't loading, but that's another issue...You've helped enormously though, thank you! – anniebabannie Oct 14 '13 at 19:31
  • @anniebabannie that sounds like a relative/absolute URI problem, try adding a `` in your page headers (or whatever the URI base should be). If your question has been answered, make sure to mark the green checkmark so your question shows up as resolved – Jon Lin Oct 14 '13 at 19:41
  • Was having this problem and it turned out to be selinux permissions. [The fix for me was here](http://stackoverflow.com/a/28589819/3585500). – ourmandave Dec 28 '16 at 01:56
0

If you use Apache, take a look in config file.

LoadModule rewrite_module modules/mod_rewrite.so

AllowOverride All

philosophocat
  • 119
  • 1
  • 1
  • 8
  • Yep, both of those lines are in my httpd.conf file. I tried what Jon Lin (below) suggested but now I'm just getting "Forbidden You don't have permission to access /my_base_url/ on this server." – anniebabannie Oct 14 '13 at 19:17