Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter route not working

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?

like image 388
LoneWolfPR Avatar asked Dec 04 '22 20:12

LoneWolfPR


2 Answers

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.

like image 137
Mathan Avatar answered Feb 08 '23 13:02

Mathan


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.

like image 29
Phil Sturgeon Avatar answered Feb 08 '23 12:02

Phil Sturgeon