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 wr开发者_运维问答iting this route?
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.
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.
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).
- I switched default controller back to welcome.php.
- Made a copy, called it welcome2.php. Class renamed accordingly.
- Changed routes to welcome2. It worked. Same welcome screen.
- Changed index() inside welcome2.php to some echo('something'). It worked.
- Renamed welcome2.php to read.php, class accordingly. Changed it in routes. It worked.
- Copy-pasted entire code from original ReadController.php into read.php. It worked.
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...
精彩评论