I am working on codeigniter 3.1.8. It works fine on my localhost. However, when I push it to FTP server, I can only access the the default controller page. When I tried to access other view that has other controller, it gives me error '404 Not Found'
config :
$config['base_url'] = 'https://*****.net/my_project/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['enable_hooks'] = FALSE;
$config['encryption_key'] = 'xRUqKhsoZ5qV6y3kqARFJFdPqJvp7X2z';
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = sys_get_temp_dir();
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
route :
$route['default_controller'] = 'main';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
I have tried several .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /materials-library/index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
and
<IfModule mod_rewrite.c>
RewriteEngine On
# Set the rewritebase to your CI installation folder
RewriteBase /sandbox/ci/
# Send everything to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Any help will be very appreciated. Thanks!
Try this, it's working for me. Make sure The file must be called ‘Yourcontroller.php’, with a capital ‘Y’.
.htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Make sure you have loaded uri library (application/config/autoload.php)
$autoload['helper'] = array('url', 'file');
Check out controller naming convention here:https://www.codeigniter.com/userguide3/general/controllers.html. Hope this will help you.
Greeting!
it's normal problem and For fixed it you have to define .htaccess file in you folder. as bellow
both file in your folder.
put this file in your main folder and assign name Of .htaccess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
put this file in your application folder and assign name Of .htaccess
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>
1) first controller name and class name first character capital letter
example :: CapturistaCtrl
2) go to config changes ::
-> $config['index_page'] = 'index.php'; remove index.php
-> $config['uri_protocol'] = 'REQUEST_URI'; remove (REQUEST_URI)
3) .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
set .htaccess file
List item
Related
Routes not working and default controller showing error 404 when I am setting welcome as a default controller then all routes defined with the welcome controller working but my other routes and url not working.
$route['default_controller'] = "welcome";
$route['testRoute'] = 'welcome/test';
$route['testRoute/(:num)'] = 'welcome/test/$i';
All above routes are working with only welcome controller.
$route['default_controller'] = "login";
$route['loginMe'] = 'login/loginMe';
$route['logout'] = 'user/logout';
Showing error 404 for all controllers and functions.
If you put index.php after domain this will work.
http://www.example.com/index.php/login/
You should remove index.php from url by replacing in config and .htaccess
replace in config.php
$config['index_page'] = 'index.php';
by
$config['index_page'] = '';
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$0 [L]
This is what worked for me:
In config.php of config folder, use: $config['enable_query_strings'] = FALSE;
Use $config['uri_protocol'] = 'AUTO';
Use $config['index_page'] = '';
Also remember to set your base url. Mine is: $config['base_url'] = 'http://localhost/code';
Finally use the following htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /code/index.php/$1 [L]
</IfModule>
NB: Remember to edit your path to index.php in the htaccess file. Hope this works for you
I will try to explain my problem as simple as possible.
My index URI is working as well and displays my "test" message.
https :// domain.com /
But other URIs doesn't work and displays "File not found" message.
https :// domain.com / about
Whereas, this URI is working like i want :
https :// domain.com / index.php / about
I really don't understand why, can someone help me ? thanks for your help ! :)
my route
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';
my .htaccess
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^pages/view(/)?(.*)$ /$2 [R=301,L]
RewriteRule ^pages(/)?(.*)$ /$2 [R=301,L]
RewriteCond $1 !^((user_guide|img|css|js|scripts|fonts)\/.*|index\.php|assets/|robots\.txt|.*\.css)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
my controller file name
Pages.php
my controller class
<?php
class Pages extends CI_Controller {
public function view($page = 'home')
{
echo'test';
exit;
}
}
?>
my config uri protocol (i've already tried with QUERY_STRING and PATH_INFO)
$config['uri_protocol'] = 'REQUEST_URI';
I would be really happy to get your help !
try using the following in .htaccess and check.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
I have finished a project and it works fine with my local server however when I put it on a live server, it gives me 404 Not Found - 404.html when I tried to access other pages. Only index.php is working the rest is not. I am using codeigniter 2.2.0. To check if there's a problem with my code I uploaded default codeigniter. I have only two pages welcome.php and one.php. Here's the live url, http://www.fhi365.com/
here is my config file.
$config['base_url'] = 'http://www.fhi365.com/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
Here is my constant
define('BASEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/');
here is my route
$route['default_controller'] = "welcome";
$route['404_override'] = '';
Here is my controller
public function index()
{
$this->load->view('welcome_message');
}
public function one(){
$this->load->view('one_view');
}
I did not touch .htacces.
Can somebody help me.
Thanks.
You should trust codeigniter base_url() OR site_url() . They always return the right url.
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
You must pay attention to .htaccess. If is enable
if ROOT
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
If SUBFOLDER
RewriteEngine on
RewriteBase /directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
This is how the problem was solved.
#Florin said to trust codeigniter.
So this is my config
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
#Shaiful Islam said that I need to put "?" to index.php on my constant.
This is my constants
define('BASEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/index.php?/');
Wew! This works fine for me.
I'm trying to setup codeigniter for our website.
if I want the main page to be http://example.com
and my folder structure looks like this:
public_html\
application\
common\
system\
how do I setup codeigniter to show the page when going to http://example.com? I'm getting a 404 error when viewing it.
I edited config.php, but im not sure what to put for my base url.
my htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
my routes.php
$route['default_controller'] = "HomeController";
$route['404_override'] = '';
my HomeController.php
public function index()
{
$this->load->model('HomeModel');
$this->load->view('templates/header');
$data['result'] = $this->HomeModel->function1();
$this->load->view('index', $data);
$this->load->view('templates/footer');
}
my HomeModel.php
<?php
class HomeModel extends CI_Model{
public function index()
{
}
public function function1()
{
$query = $this->db->get('work_orders');
//return $query->result();
return $query->result_array();
}
}
EDIT2:
Edit your default_controller from HomeController to homecontroller Like this:
$route['default_controller'] = "homecontroller";
and rename (if needed) your controller from HomeController.php to homecontroller.php and in your Controller itself call it Homecontroller.
Do the same for the model. call it homemodel.php (or home_model.php) in your directory and Call it Homemodel in your model itself.
Also clear your browser cache.
EDIT1:
Rename your model. I guess you called your model HomeModel.php. just call it home_model.php. this should fix your problem.
Your .htaccess file should look like:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
This is just copied from my server and it works great.
After then, change your default_controller to:
$route['default_controller'] = "the default controller";
and if public_html is a folder you created your index page should be:
$config['index_page'] = "public_html/";
otherwise leave it blank. (if it's your server's httpdocs)
should work :)
At your router.php in config folder there is an line
$route['default_controller'] = "your controller name";
add your controller that you want to display defaultly
You can make base_url empty:
$config['base_url'] = '';
Try this working .htaccess conf:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
IF nothing helps then hosting doesn't support mod_rewrite apache module
I'm stuck with redirect loop when I deploy the files from localhost to my server.
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
The site is multilingual and I'm using .htaccess file to remove the index.php from the uri. I'm trying to deploy the site to a subfolder in my domain (i.e http://www.mydomain.com/subfolder) and ideally I want the urls like this (http://www.mydomain.com/subfolder/en/welcome)
My .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
I have also tried:
RewriteEngine on
RewriteBase /subfolder/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
My config.php:
$config['base_url'] = 'http://www.mydomain.com/subfolder/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
My routes.php:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['^../products/(:num)'] = "products/products_list/index/$1";
$route['^../products'] = "products/products_list/index";
$route['^../products/detail/(:num)'] = "products/product/index/$1";
$route['^../(.+)$'] = "$2";
And finally MY_Config class for i18n:
class MY_Config extends CI_Config {
function site_url($uri = '')
{
if (is_array($uri))
{
$uri = implode('/', $uri);
}
if (function_exists('get_instance'))
{
$CI =& get_instance();
$uri = $CI->lang->localized($uri);
}
return parent::site_url($uri);
}
}
This setup works fine in my local environment, I access via http://local.subfolder.com, I set a virtual host to do this, but this setup doesn't work when I deploy to the server in a subfolder.
I would be really glad if someone can point where the problem is. Sorry for the long post, but wanted to give as much as information.
Thanks in advance
I'd try removing the trailing slash from RewriteBase
RewriteBase /subfolder
And also modifying your RewriteCond
RewriteEngine On
RewriteBase /subfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
I've noticed that using the ? before /$1 seems to work sometimes in CI too.
Very useful doc:
http://codeigniter.com/wiki/mod_rewrite/
if u want to use the htaccess for a particular folder., u just put your htaccess with in that folder. for ex.,
if ur using five virtual hosting like v1,v2,v3,v4,v5. And if u want to use your htaccess in v3, just put that file within that folder.