I have four identical pages that only differs in some identifiers but the logic is very much the same. All of them works on localhost. Three of those pages works okay on live server, but one of them returns a 404 for some reasons I can't understand.
I use XAMPP 3.2.2 and Sublime for developing it on local. I moved it to GoDaddy Deluxe Linux for live. My Codeigniter version is 3.1.10.
I already tried answers from most of the questions on StackOverflow:
All controller and model names' first letters are capitalized in the file name and inside the file.
All of the .htaccess codes on here: https://github.com/tasmanwebsolutions/htaccess_for_codeigniter
I have two .htaccess files, one of them is inside the application folder, and one is outside. I don't know if that's confusing the system? But I have another website on a different hosting that has the same .htaccess files and they're working okay. And anyway, if that's confusing the system, why does it only affect one of the four identical pages?
.htaccess outside application folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
.htaccess inside application folder:
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
All of the controllers of the four files has this up top:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//session_start(); //we need to call PHP's session object to access it through CI
class Question1 extends CI_Controller
{
and the rest is normal code stuff that are working on three of those four files.
In config. php I have:
$config['uri_protocol'] = 'REQUEST_URI';
and base_url is great.
Models and views are okay, as far as I can see, and the rest of the website is functioning alright with the included .htaccess. My routes are working okay, as well.
I'm so lost right now.
PS. I have a custom 404 page. When I input assessment.com/index.php/question1 it shows that custom 404 page. But when I open assessment.com/question1 it shows codeigniter's own 404 page (and not my custom one, for some reasons). I think that tells something, I just don't know what.
EDIT
Here's my routes.php:
$route['default_controller'] = 'home';
$route['404_override'] = 'Error404';
$route['translate_uri_dashes'] = TRUE;
I opted not to do
$route['question1'] = "Question1";
in routes because it doesn't change anything.
Check your APPLICATION ENVIRONMENT mode. You can find it on your project root_folder/index.php and at line no. 57.
define('ENVIRONMENT', 'production');
Change the ENVIRONMENT mode into the development mode, that is
define('ENVIRONMENT', 'development');
Then refresh your applications again. If you see CodeIgniter default error you can understand your CodeIgniter application are running ok and check out the error.If it doesn't show any error then your .httaccess has any error. I solved it my 404 error with this code, you can check this out.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^asset.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Answering this for the others who might come across the same problem.
Okay so user Don't Panic suggested I echo just "question x" in the problematic controller, and when I did that, the 404 error went away and it echoed the "question x." So definitely it's my controller that has the problem and not my routine or .htaccess files.
Now this controller is designed in such a way that it calls first an ID from the database before it shows anything. After I echoed "question x" I realized that the ID it is calling from my database has a value of zero. So, unsurprisingly, from the controller's point of view, the page doesn't exist! Hence the 404.
I've fixed it now by updating that table from my database and giving the ID a value it should already have had in the first place.
Related
Let me inform you this first. This application is working pretty fine on live server currently, however we needed to move it to a different server with a different domain.
Issue is: It gives 404 error on every other page except for index. Loading through index.php works fine.
For an example:
www.test.com/main/login //This gives 404 error
www.test.com/main/index.php/login //This loads fine
Because everything is working fine currently, I made changes only in $config['base_url'] and in database config file. There have been no other changes in any of the files.
Also, this solution provided by somebody in a different questions is already tried out and this doesn't work. Solution is to create .htaccess file with below code & setting $config['index_page']='' :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Current server is VPS & provider is GoDaddy. New server is Shared hosting and provider is GoDaddy. I'm not getting the root cause of this happening, can somebody point out to the possible solution?
EDIT
I'm attaching a screenshot for an error, it's not typical 404 error page. In case this helps.
For Godaddy, you need to alter this 2 things.
In your .htaccess file, replace
RewriteRule ^(.*)$ index.php/$1 [L]
With the following:
RewriteRule ^(.*)$ index.php?/$1 [L]
Then is your application/config/config.php :
$config['index_page'] = '';
Both this changes should help you resolve your issue.
I don't usually post messages on the web to get help but I feel that I have tried everything and I am stuck.
I wanted to upgrade CodeIgniter from version 2.2 to version 3.0.3 (I tried v3.0.2 too) and I followed the corresponding guide on codeigniter.com. But now, only the default controller is loaded, no matter the url.
I have searched on the web and I have found out that it could come from:
the htaccess
the application/config/config file
the application/config/routes file
the new Ucfirst rule for the filenames (controllers, models...)
But I still don't have the solution...
The files in "applications/controllers" are all Ucfirst.
Everything was working fine before (with version 2.2), so WAMP should be correctly configured (mod_rewrite enabled etc...). Moreover, I have tried and succesfully loaded a clean instance of CodeIgniter 3.
Models, Controllers and Views are loaded correctly, I can change my default controller and it will load the correct view (with requests done by controllers and models). But it only loads the default controller, no matter what the url is (in the browser). Even if it does not exist, I never have the 404 page. Except if I specify an incorrect "default_controller" (in the file "routes.php").
It has to be a routing issue...
Here is some of the tests I have done:
Table of tests
Here is my htaccess file (I have tried other ones on the web too, the result is the same):
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#Enable access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
Here is my "application/config/routes" file:
$route['default_controller'] = 'dashboard';
$route['404_override'] = 'auth/e404';
$route['translate_uri_dashes'] = FALSE;
Any help would be appreciated :-)
Thank you !
SOLUTION
$config['enable_query_strings'] was set to "TRUE" in the file "application/config/config.php". Setting it to "FALSE" solved the issue. So simple...
try putting the index method in the routes, for example instead of this
$route['blog'] = 'blog';
try this
$route['blog'] = 'blog/index';
and if that doesn't work, can you confirm you have set the correct base url in application/config/config.php ?
In codeigniter 3 wamp
I use this htaccess
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
With your error 404 over ride can not be in sub folder.
Change
$route['404_override'] = 'auth/e404';
To
$route['404_override'] = 'e404';
And on config.php
$config['base_url'] = 'http://localhost/your_project/';
// You can leave base url blank but not recommended because when you try to submit forms make cause issue.
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
I copied a fully functional CodeIgniter app into a new server, updated the config.php base url, and setup all database parameters accordingly.
An interesting problem I'm having is that the new install (in new server) returns a 404 for all controllers I try to access. However, when navigating to the base URL, my default controller welcome.php defined in routes.php is rendered fine on the browser.
$route['default_controller'] = "welcome";
This suggests to me that CI is running OK but there may be some other routing issue I'm not figuring out.
My .htaccess is
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
which works fine on the other server.
Any ideas what I'm doing wrong here?
Is your apache directory configuration set to AllowOverride All?
I extended the CI_Controller and made my own controller to be extended.
Now everything works fine in localhost (xampp) but when I copied the files over to my web server, I get 500 internal server error which is quite useless. Odd to me is the fact, that I get internal server error instead of codeigniter generated error.
Things I have tried so far:
1) tried libraries folder instead of core for MY_Controller
2) I have had problem with server only accepting lowercase file names so I tried my_controller and changing config file prefix, main.php extension and so on.
Both of these seems like useless tries anyways, cause I didn't get error saying it can't be found or something similar.
When I change my main.php controller to extend CI_Controller, everything works fine.
I know I haven't provided much information, but I have no idea what to provide. Again, it works in localhost.
Thanks for any input you might have.
Try changing your config.php to.
$config['index_page'] = '';
and the .htacces of the site to:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
Hello and thank you for taking the time to help me solve my problem. I like to build all of my web projects using a simple MVC Framework I have created along my travels. I seem to be having a problem getting the .htaccess file to work correctly on specific servers.
For example...
If you go to:
http://thomsonbrothersindustries.com/northside/ and attempt to access a page (right now only "About Us" is functional - http://thomsonbrothersindustries.com/northside/about) but as you can see the "about" page just directs you to a 404 Error.
Now, if you go to: (the same site, but on a different server)
http://ericzdisposal.com/northside/
http://ericzdisposal.com/northside/about
everything works fine...
Here is the .HTACCESS file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]
My privileges are limited on the server that is currently not working and I'm still working on getting better access to domain tools, but in the meantime I'm just trying to get a better idea of the problem and hoping there might be an easy fix in my future.
In addition to what #bigman suggested, make sure that AllowOverride directive setting is not very restrictive for your website directory. For mod_rewrite to work in .htaccess, you need to set AllowOverride FileInfo, but for testing purposes, you can set AllowOverride All.
Looks like adding the directory into the .htaccess file did the trick!
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ **/northside/**index.php?rt=$1 [L,QSA]
I didn't realize this was important because on the other server it did not matter
Thanks all!