Nginx & PHP5-fpm + CodeIgniter or Kohana = 404 error? - codeigniter

Ok, this is not a rewrite error because I did not touch the conf file.
I used http://www.farinspace.com/install-and-configure-nginx-server/ to make the web server.
The thing is CodeIgniter & Kohana does work on http://url.com/sub/ and http://url.com/sub/index.php
But, it does not work with http://url.com/sub/index.php/welcome or any controller (am I calling that right?), I get a 404 Not found.

am I calling that right?
Obviously not. 404 error in kohana / codeigniter means that no matching controller / action could be found. Additionally 404 error by the server means that the overall resource was not found.
Nginx requires a different server configuration than apache. RewriteRule is only one example.

Related

Laravel gives 404 error for root (/) url but other urls work fine

I'm using laravel 6 and for some reason when using Route::get('/','HomeController#Index') I get 404 not found error but any other urls like Route::get('/home','HomeController#Index') works just fine.

How to call sitemap.xml in codeigniter application

i have added sitemap.xml file to my codeigniter project.
And i call it on my localhost like that : http://localhost/demo/sitemap.xml
it runs without any issue.
But when i run it on live server http://example.com/demo/sitemap.xml
it says 404 page not found.
What is issue ?
you need to add below things in your config/routes.php file
$route['sitemap\.xml'] = 'demo/sitemap'; // your navigation path i.e. your controller_name/function_name

Unable to run the app on hosted server

I have just installed Ci framework and tried on my local some basics according to the tutorial.
http://ellislab.com/codeigniter/user-guide/tutorial/static_pages.html
On local machine, everything was OK and page was displayed.
Than I upload project to the server (I am using wedos web hosting where I already have som web which is working correctly) but this is not working for the application which I copied it here. When I type the URL I got 404 error.
On my webhosting service I have www folder where i put my index.html file. Than when i type www.mydomain.eu I get this index.html file. Than I have subfolder www/folder/index.html Than when i type www.mydomain.eu/folder i get this page so it is ok.
Than i have www/folder2/here i unzip CodeIgniter framework and when i type www.mydomain.eu/folder2, 404 Page Not Found appears. The error is not general error from browser but generated from the CI framework.
I have created my own controler in application/controllers/mycontroller.php
<?php
class Mycontroller extends CI_Controller {
public function view($page = ‘enter_form’)
{
$data[‘title’] = ucfirst($page); // Capitalize the first letter
$this->load->view(‘templates/header’, $data);
$this->load->view(‘pages/’.$page, $data);
$this->load->view(‘templates/footer’, $data);
}
}
And I have following structure of views:
views/pages/enter_form.php
views/templates/header.php and footer.php
And the following settings:
1) $config[‘base_url’] = ‘’; but I have tried ‘http://mydomain.eu/’ and ‘http://mydomain.eu/www/’ or ‘http://mydomain.eu/www/folder2/’
2) $route[‘default_controller’] = ‘mycontroller/view’;
$route[’(:any)’] = ‘mycontroller/view/$1’;
Thank you for any help
Sounds to me like there is either a configuration issue or a rewrite issue going on. Do you have a .htaccess file in your CI root folder where your index.php file lives? Seeing that you are depending on the CI to pick up any uri and reroute it to a specific route, this might be the issue. I've ran into issues with this before on different hosts. Make sure mod rewrite is enabled and make sure your .htaccess is something similar to this:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|assets|uploads)
RewriteRule ^(.*)$ /index.php/$1 [L]
Ok, so it seems like the typo somewhere, because when I used the default CI welcome pages, it works. So I will try to find the typo myself and i will see...

CodeIgniter returns 404 for all routes but works

I have strange problem with CodeIgniter and routing system and can't find solution for it, so: I have several routes such as
'forum/(:num)'
=> 'forum/category/$1',
'forum/(:num)/(page:any)'
=> 'forum/category/$1/$2',
and them works, but return 404 code in header.
I mean I don't get 404 page, correct HTML returns and page's content displays correctly for my forum's categories. But I'm getting 404 in header (Network tab in Firebug), so I can't work with POST data correctly.
If I request /forum/ - 200 Ok returns, but when I trying to get routed page, I get right page, but with 404 Not Found.
I'm using PHP5.4+Apache2 on Linux host, if it will help You to give me solution.
I've found solution! Maybe it will save someone's time.
Problem wasn't in CodeIgniter, I've found solution in activation mod_rewrite. Yes, that worked, but wan't activated in Apache.
Just try to do
sudo a2enmod rewrite
and restart apache service after
sudo service apache restart
And all routed pages will return 200 Ok
None of these worked, but I did this instead:
At the end of my controller I put this:
$this->output->set_status_header('200');
and actually though that worked, the problem turned out to be a controller name that conflicted with a real directory name...

Post array always empty on CodeIgniter application running on nginx

I have nginx 1.0.2 installed on Ubuntu 11 with php 5.3.5 running with FPM/FastCGI.
On a codeigniter applilcation of mine i get the following problem.
I have a simple login form with a username and password field. When I submit the form the $_POST array is empty. So is $this->input->post('username') and $this->input->post('password').
The application works fine on apache. I tried creating a simple test form on a simple php file and $_POST data worked perfectly. I can provide configuration files if needed. Any ideas ?
Update:
It finally worked. There were some redirects in my vhost config which were causing loss of post data. The working vhost config can be found here: http://codeigniter.com/forums/viewthread/90231/#455528
I think I know the issue now. The fact that it's returning 404 and processing your script tells me that the error_page is what's doing the 'rewrite' to get the request to /index.php. An error_page to a non-named location will transform the request into a GET, so the error_page 404 /index.php is doing an internal redirect to /index.php, but it's stripping the request body in the process (and the lack of an = means the status code isn't overridden by the error_page target). I'm not sure why all those ifs aren't performing the redirect (if processing in nginx is really weird, so it's a good idea to avoid them), but I think if you use a named location for your error page, that will preserve the request body and fill in $_POST. Try replacing your current error_page directive with:
location #redir {
rewrite ^ /index.php;
}
error_page 404 = #redir;
check these:
<form method="post">
you using the post method?
try running the profiler:
$this->output->enable_profiler(TRUE);
seeing any POST output there?
I was using my own PHP framework with similar URI rewrites as CI and on Nginx server had similar issues, cause my forms had actions like: action="admin/login/post" and I had to change them to end with .php action="admin/login/post.php" so they could work, but this requires you to change the URI rewrite of your CI class to replace that .php from the uri string.
I had a similar problem and i tried everything mentioned here. It was very simple when i figured it, I had not named my input variables in the form. I had missed the name parameter.
<input type="name" placeholder="Name" name="name">

Resources