Reputation: 4090
I have the following routes in my routes file:
$route['default_controller'] = "main";
$route['404_override'] = '';
$route['testroute'] = "main";
As you can see all I want is when someone goes to mydomain.com/testroute it should just route back to the default controller. However when I go to that I get a 404 error. Am I doing something wrong in the way I'm writing this route?
Upvotes: 5
Views: 18744
Reputation: 151
You have to create the .htaccess
file in your app.
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Please paste this code in your .htaccess file.
Upvotes: 15
Reputation: 1296
Listen, this is the stupidest answer ever, but this is my experience with the similar situation - that just happened. I was helpless, but it started working - here's how.
I have one controller, caller ReadController.php (class is called the same). Route was the same:
$route['default_controller'] = "ReadController";
Calling it with www.martinjovanovic.com/DSi1.5-v01/index.php/ReadController/
- worked.
But calling it with just martinjovanovic.com/DSi1.5-v01/
just wouldn't work at all.
Base URL was that of my domain and folder: wwww.martinjovanovic.com/DSi1.5-v01/
No changes to htaccess whatsoever, I left it default (Deny from all).
That was it. Same thing started working.
The only difference between the original ReadController.php and the new read.php was in the first line. In my new read.php I kept the first line that was actually missing in the old ReadController.php (my developer ommited it, I guess):
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
This was immediately after the opening php tag. That was the only difference. I don't get why it made such difference. Maybe it's not about it at all. Nontheless, it worked.
And the moral of this story is: I started from what worked in the first place, and kept slowly changing it towards what I need, until it worked...
Upvotes: 1
Reputation: 30766
LoneWolfPR hit the nail on the head with his comment, you are using FastCGI which requires a different htaccess.
Can you try using this one?
https://raw.github.com/pyrocms/pyrocms/develop/.htaccess
I am tempted to propose we add it into CodeIgniter 2.1-dev to save this question coming up 15 times a day. Let me know if it works or fails.
Upvotes: 1