CodeIgniter: 404 Page not found after push for server - php

I did some apps on my local machine, runs ok, but after send that to the server I am getting 404 error page, I tried all methods but none works, can you help me with that?
a2enmod rewrite is on.
I found in google I need use in the server the same version of my php I have in my localmachine or my app will not run, that is true?
my local:
application/config/config.php
$config['base_url'] = 'http://localhost:8888/app/';
$config['index_page'] = 'index.php';
my server:
application/config/config.php
$config['base_url'] = 'http://example.com/app';
$config['index_page'] = 'index.php';
I tried too:
application/config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
I got stuck on that, can you help me with that?

Try this code in your .htaccess file, you are not providing access for your CodeIgniter Directory.
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /app/index.php/$1 [L]

Do This Configurations
In your config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
in config/routes.php file
$route['default_controller'] = '';//default controller name
$route['404_override'] = '';
then in .htaccess(this should be place out side of application folder)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

The error was: in controllers was like that: user.php so i renamed for User.php, i not understand well that, but fixed online my code.
using user.php run in my local but not in live, if somebody know why, please leave a comment too.
thanks all for the help.
cheers.

Related

Getting error 404 when accessing my web application on another devices

Im trying to access my web application on others devices but when i click the login button it gives me a 404 error - the page doesnt exist.
On my computer works fine but in others i get that error.
I've check capital errors on the controllers names but it all seems to be fine.
Anyone have any idea on what it might be?
Config file:
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/CodeIgniter/mponto/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['url_suffix'] = '';
htaccess file:
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]
Routes:
$route['default_controller'] = 'Pages';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['login'] = 'Utilizador/login';
maybe you should change
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/CodeIgniter/mponto/'
to
$config['base_url'] = 'http://#yourdomain.xxx/CodeIgniter/mponto/'
and you should use route default controller for your login not pages
i dont know it will work or not , i am newbie
Try this code
$config['is_https'] = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? true : false;
$config['base_url'] = 'http'.(($config['is_https']) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].str_replace('//','/',dirname($_SERVER['SCRIPT_NAME']).'/');
or
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/CodeIgniter/mponto/';
or
$config['base_url'] = 'http://Yourdomainname/CodeIgniter/mponto/';
You can just change base_url in config file.
$config['base_url']='http://base_url/path';

Only default controller is working and the rest is 404 not found

I'm using codeigniter on my wamp and everything is fine but when I upload it on live server the default_controller is working but the other controller are 404 not found or "The requested URL /Sample_controller was not found on this server".
Here is my sample controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Sample_controller extends CI_Controller {
function __construct(){
parent::__construct();
}
public function index(){
print_r('Hello World');
}
}
and here's my config.php:
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
$config['allow_get_array'] = TRUE;
and this is my router.php:
$route['default_controller'] = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
and my .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /folder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !www.sampleurl.com$ [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteCond $1 !^(index\.php|assets|user_assets|tmp|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
if I tried this sampleurl.com it's working fine and will direct me to my default controller which is the login but if i tried this sampleurl.com/sample_controller or sampleurl.com/login it will lead me to 404 not found The requested URL /sample_controller was not found on this server. Apache/2.4.7 (Ubuntu) Server at sampleurl.com Port 80
I hope someone can help me on this
I tried changing them to:
$config['uri_protocol'] = AUTO
$config['enable_query_strings'] = TRUE;
and it's still not working.
You need to add a route for that controller to work
$route['sample_controller'] = 'sample_controller';
For every new controller you create you need to have a route for it
According to your code, you may have these 2 issues:
1- As per documentation you are required to make your controller filename first character Uppercase.
2- Try adding a question mark "?" in your .htaccess file's last rule. Also remove the "/" before "index.php" check the code below.
Current code:
RewriteRule ^(.*)$ /index.php/$1 [L]
New code:
RewriteRule ^(.*)$ index.php?/$1 [L]
Just simply change
RewriteBase /folder
This line of code in your .htaccess file to appropriate folder name of your project and it will work fine.

CodeIgniter .htaccess rewrite not working on Live Server

I have a little problem with Code Igniter project, I have a .htaccess file to rewrite the index.php. It works great if I put my projects on Local Server. I am using WAMP Server. But now I have uploaded it on Live Server for example (godaddy,00webhost). And it is showing error :
404 Page Not Found.The page you requested was not found.
My .htaccess is here :
RewriteEngine on
RewriteBase /directory_name/
RewriteCond $1 !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favico​​n\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
and my config.php setting is here:
$config['base_url'] = 'http://example.com/directory/' ;
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
I have tried many solutions on web but not enough lucky to find one who helps me. I am stuck since 3 days. Anyone Help me.
If you are trying to host the website in a subfolder, make sure you enter the correct info in your htaccess and config:
Change RewriteBase /directory_name/in htaccess to RewriteBase /ci_foam/
Change $config['base_url'] = 'http://example.com/directory/' in your config to $config['base_url'] = 'http://php0713061.herobo.com/ci_foam/'
You always need to make sure these values matches your current server setup.

Only welcome controller loading in codeigniter when hosted under cpanel

The app which i'm creating using codeigniter is loading on my localhost. But when i uploaded the same into cpanel its showing "404 Page Not Found".
I'm able to access default welcome controller other than this it shows 404 page not found.
Below are my configuration in application/config/config.php
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
.htaccess configurations are as follows
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]
configuration in application/config/routes.php are as below
$route['default_controller'] = 'login';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
If I change the default_controller to welcome then welcome is loading fine.
--Thanks in advance
As said in the comments : Your controller's file name must start with an uppercase.
See http://codeigniter.com/userguide3/changelog.html
Changed filenaming convention (class file names now must be Ucfirst
and everything else in lowercase).
:-)

CodeIgniter - Default controller not loading automatically

I have a default controller set:
$route['default_controller'] = "Home";
However, when I go to http://mydomain.com/, it says 404 Page Not Found, but when going to http://mydomain.com/Home, the controller loads fine. What could be the problem? I've been wracking my head for hours. My htaccess is posted here if needed. Thanks!
Turns out my problem was somewhat unrelated. I had to rename my default controller php file to lowercase and the controller class name to lowercase and everything started to work. When CI looks for the default controller file, it searches in lowercase for the file; if I name my controller file "Home.php" instead of "home.php," CI misses it on Linux (since Linux file systems are case sensitive).
There is nothing wrong with your routing, the problem is with your htaccess file. Try removing
ErrorDocument 404 /index.php
You have probably some .htaccess problem.
Tray this way:
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
config.php
$config['base_url'] = 'www.homepage.com';
$config['index_page'] = '';
routes.php
$route['default_controller'] = "yourcontrollername";
$route['404_override'] = '';
Without any additional information & code from your configs/controllers, I'd suggest checking config/config.php for these (both should be empty in normal cases):
$config['base_url'] = '';
$config['index_page'] = '';
IIRC, I have seen similar issue and it was related to these config variables. Hopefully this helps you a bit.
I sure this .htaccess solved all ubuntu users...
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]
I have a default controller set:
$route['default_controller'] = "home";
it's working for me.

Categories