Codeigniter - 404 Page Not Found error - codeigniter

codeigniter working on my local machine but not on server.
administrator/application
administrator/system
administrator/assest
I tried some .htaccess files but codeigniter not working.

On codeigniter 3 Check all your controller and model make sure the filename and class name have there first letter as uppercase example Welcome.php and class Welcome
Also if you have not configured your index.php to be removed on either codeigniter 2 or 3 versions then you will need to add in url each time you use a link.
Live Server URL Example
http://www.example.com/index.php/site
Localhost URL Example
http://localhost/project-name/index.php/site
Some Htaccess Example Link
How to remove index.php codeigniter 2 & 3

Related

Need to change hmvc routes in CodeIgniter

I have CodeIgniter HMVC application and I want to change route as per requirement.
Now I have website/product/detail/url, and I want to change it with website/url.
Once I set URL from admin side it will redirect to my route.
This is what I have now:
$route['Products'] = "Products/detail/d101productdatatest(this is url)";
And I want in my url like website/url and it will open same page what I have with website/product/detail/url
From the given library:
https://www.codeigniter.com/userguide3/general/routing.html
routes as above:
$route['controller/function'] ='website/Products/detail/d101productdatatest';
But as per your given question:
you cannot manipulate url using routes
you can map same function with different url using routes
you have to use .htaccess to redirect to specific url after hitting the previous given url.
htaccess example:
Redirect /index.html /new/
Redirect /index.html /default.html
Redirect /private/ http://www.example.com/private/
Redirect /img/logo.gif http://www.example.com/images/logo.gif
Hope this answer helps you out !!
cheers

Index.php in all Urls and HTTPS Redirect Issue

1st Issue : In Every Urls Keep index.php.I want to Remove Index.php from every Url
2nd Issue : I have Installed SSL . So Site Working file in Https Version . But If anyone Reach a Urls without HTTPS version like http://www.test.com/contact.php it should Redirect to https://www.test.com/contact.php But it's Redirecting to Home Page
Wish will Get Solution
To remove index.php from all pages,refer the below link.
Click here

CodeIgniter always and only shows default controller or 404 page

I am asked to study about CodeIgniter but I haven't even heard about it before, so I'm trying to go through the textbook and official tutorial. But I can't even successfully display a Hellow World...I've tried to search the solution for a while but none of them helps.
Here's the specific problem. I'm building a CodeIgniter environment with MAMP, PHP version is 5.6.2 and CodeIgniter version is 2.2.0. But no matter what I do, the site can only show me the default controller or 404 page.
First of all here's "hello.php" in controller folder:
<?php
class Blog extends CI_Controller {
public function index()
{
echo 'Hello World!';
}
}
?>
I haven't set the mod_rewrite yet so I simply goes to this address:
localhost:8888/CodeIgniter/index.php/hello
And I only get a 404 page. So I tried to modify uri_protocol in config.php. I tried all of them, and QUERY_STRING and ORIG_PATH_INFO worked fine at first. I thought I succeeded. But I was wrong. I then setup a mod_rewrite with .htaccess file and I can only get a default controller (which is welcome page). I thought I must did something wrong in my .htaccess file so I tried to edit it but it doesn't work, so I tried to remove the file and go back to index.php/hello again, then I found that it can't work anymore, what I get is only a default welcome page.
I then tried to restart the server, modify index_page in config.php to 'index.php?', move CodeIgniter to root directory (I mean instead of localhost:8888/CodeIgniter/index.php, I removed CodeIgniter folder and just go to localhost:8888/index.php), totally remove the current CodeIgniter folder and download it again from official site, and of course tried other choices of uri_protocol. But nothing helps. What I get is still only default controller or a 404 page.
In summary, in config.php file, if I set
$config['index_page'] = 'index.php';
then
$config['uri_protocol'] = 'QUERY_STRING';
$config['uri_protocol'] = 'ORIG_PATH_INFO';
returns the default controller (even if I try to access a page which actually doesn't exist in controller folder), and other uri_protocols return 404 page.
Else, if I set
$config['index_page'] = 'index.php?';
then
$config['uri_protocol'] = 'PATH_INFO';
$config['uri_protocol'] = 'ORIG_PATH_INFO';
returns the default controller (also even if I try to access a page which doesn't exist in controller folder), and others return 404 page.
Also I thought it may be a problem with MAMP but even if I upload the whole site onto a VPS server (CentOS 6.5, php version 5.3.3) the totally same problem occurs.
Anybody has some idea?
First of all, to remove the index.php from your url, create a .htaccess file in your site root, and add the following code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
and then in your config/config.php file :
$config['base_url'] = '';
$config['index_page'] = '';
set the rest config parameters as usual.
Now, you are using the url localhost:8888/CodeIgniter/index.php/hello to access your application. This is wrong (unless you are routing the url). You have to load your controller which in turn loads the view for you. So, now use:
localhost:8888/CodeIgniter/blog
Again. One more thing. In the constructor of your Controller, you will have to call the parent constructor so that you can use loader class to load librariee, view, models whatever.
Now lastly, your best bet is to go through the documentation well. You have tried but not tried enough! Good Luck.
Umm well thanks for your help! A friend on Twitter told me that the class name was wrong, it should be the same as the php file (in this case, it should be class Hello extends CI_Controller)
After that, all things goes OK!
I was having this issue with CodeIgniter 1.7 when using it through the command line (CLI). I had to modify the _fetch_uri_string() function in the CI_URI class (system/libraries/URI.php) to see if $_SERVER['argv'][1] is set to find the URI being used. To find where your project's URI is present with your global $_SERVER variable, I would just do a var_dump($_SERVER); exit(); at the top of your index.php file.
Changes I made to the _fetch_uri_string() function highlighted:

In Codeigniter some URIs pass through index.php, some don't

Basically one controller (controller/topics.php, http://192.168.1.50/topics) gets passed through CI's index.php like its suppose to, yet another (controller/user.php, http://192.168.1.50/user) for some odd reason simply doesn't pass (I get an 404 error in browser). CodeIgniter and/or Apache2 are doing something funky and I can't figure it out: '.../user' gives me Apache's 404 page, yet '.../User' gives me CI's 404 page which means CI grabs URIs with uppercase controller names and ignores some URIs with lowercase controller names (and then Apache tries to handle the URI).
Any ideas why and how to resolve?
P.S. - Yes, I did post my issue in CI's forum but I'm not having luck with their help. I'm running CodeIgniter 2.0.2 on a Linux distro (Ubuntu 10.10 with LAMP).
The problem was that the rewrite condition syntax is saying don’t route folders that BEGIN with i, c, j or u instead of folders whose name IS i, c, j or u. Coincidently my controller names which weren’t loading started with i (idea) and u (user).
I could just rename my static folders to their full names (“uploads” instead of “u”) and update the rewrite condition and resolve this issue, but I’d like to keep the names the same. Anyone happen to know the correct syntax for the rewrite condition to match exact names (instead of like or begins with)?
Check your controller name, the most common thing people (I find) do is copy their 'main' controller (say topics.php) and rename the file name to whatever.php
They start developing and the controller name stays 'Topics'. 404 is thrown due to the controller not being found (not the actual file)
ex:
class Blog extends CI_Controller {...
if the above code is in a file called stuff.php. You will get a 404 if you are calling /stuff
I ran into a similar problem yesterday. The default controller can have an uppercase file name but any other controller would produce a 404 when uppercase. This was on a MAMP setup.
Make sure your controller reflects the file name as well.
class User extends CI_Controller {
in your htaccess... instead of
RewriteRule ^(.*)$ /index.php/$1 [L]
try
RewriteRule ^(.*)$ index.php/$1 [L]
and in your CI config set base_url as instructed (include trailing /!)
$config['base_url'] = 'http://www.site.com/';
That should do it.

Codeigniter: Routes only visible when entering /index segments

I'm working on my first project with codeigniter 2.0 and have a bit of a problem.
On my localhost (a MAMP installation) everything works fine with the routes. Only when i add a copy on my domain, change the base url and other necessary settings like my database settings it works fine for like 99%. I can't access my other controllers directly without adding the /index route. For example when i want to visit the http://my_domain.com/work it'll open the 404 error page but when i enter ttp://my_domain.com/work/index it works fine. Does someone know a setting i have to change for the online version? The Htaccess files are identical.
CHeers in advance.
I found my solution. I just checked the routes.php file in my config where i added a route for every controller. I just removed these and only my default_controller route is left. Now it works fine. Just a codeigniter newbie issue.
Thanks anyways for the help #Hibiscus and #BigFatBaby
I sorted my problem by setting the following line as my .htaccess file.
RewriteEngine On
RewriteRule ^.*$ index.php [NC,L]
It'll rewrite anything after the /index.php/blaha to /blaha.

Resources