I created a project using CI(version 3.0.0), and it works perfectly in XAMPP localhost. And i upload that project to sub domain then its giving an error Click here.
I Handle Router's and config setting as well. So what is this error?? how to avoid this?? There are some answers, But not suit for this.
Config.php
$config['base_url'] = '';
$config['index_page'] = '';
Routes.php
$route['default_controller'] = 'shop';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
.htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Change the name of your controller, model, and other your class to Capitalize.
Example :
your own controller test.php change to Test.php
It should be work.
Its because your server is Linux, and Linux is case sensitive.
Related
I have installed two codeigniter in my server. One is the root of the domain and for second I've creates one new folder and installed second codeigniter there. When I am trying to access the folder, it shows error 404.
You should define base url for sub directory in your config
You can get Idea from following example code
$config['base_url'] = http://example.com/sub;
Try this Set you default base url for subdirectory
$config['base_url'] = "http://www.example.com/sub/"
Open config.php and do following replaces
$config['uri_protocol'] ="AUTO"
by
$config['uri_protocol'] = "REQUEST_URI"
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
This code run all sub directory. Hope this will help you!.
My site http://www.bishal.prtia.com/prT_base/ throw an 404 error while loading in the server.
It works perfectly in the localhost. I tried changing everything that mentioned in this forum like changing .htaccess to web.config and changing base url routing config etc but it still throws an error.
Check the following things once again:
Make sure your base_url is proper as per your website address, not localhost
Check routes.php file for default controller and make sure it is correct.
Make sure .htaccess looks like
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|images|js|css|upload|favicon.png)
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteRule ^(.*)$ ./index.php/$1 [L]
Then check following thigs:
Config.php
$config['base_url'] = 'http://www.bishal.prtia.com/prT_base/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Routes.php
$route['default_controller'] = 'your controller name (like welcome)';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
Make sure php file name of controller start with capital letter like Welcome and also inside that file as well when inherit from CI_Controller
Function inside Welcome.php:
public function index()
{
$this->load->view('your view file');
}
Thanks
You need to do few steps.
Update base_url in config.php
Update RewriteBase in .htaccess
Set Permissions
if still not workable, add error_reporting(E_ALL) in index.php and see what it says
I also faced this error. I changed my .htaccess file [WORKED FOR ME] :-
.htaccess for Live Server :-
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
.htaccess for Localhost :-
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1
http://localhost/codeigniter/index.php/user/main_page
how can you remove index.php from this url ?
Try this file. I use it in my projects
https://github.com/eborio/curso-de-codeigniter/tree/master/02-primeros-pasos
The answer is in the post that this question is ducplicated of.
This is the answer
Sean Vieira's answer:
If you are using Apache place a .htaccess file in your root web
directory containing the following:
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Another good version is located here:
http://snipplr.com/view/5966/codeigniter-htaccess/
Try this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Replace:
$config['index_page'] = "index.php"
to
$config['index_page'] = ""
if it still not work try to replace:
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI"
for more details: http://w3code.in/2015/09/how-to-remove-index-php-file-from-codeigniter-url/ check this
I know there are many issues like this but I applied everything and I don't find the correct way to do it.
The .htaccess is :
RewriteEngine On
RewriteBase /NewWebsite
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /NewWebsite/error.php
</IfModule>
In config/config.php :
$config['base_url'] = 'https://mydomain.com/NewWebsite/';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO'; // I change it with REQUEST_URI and PATH_INFO but it don't work
In server, mod_rewrite is enabled.
In localhost, everything is ok but when i uploaded it to the server, only index works (the first page that you see) but when I want to "move" around the web, i have 404 error, page not found.
I am going to show one controller and how I call it to change to another views.
class Products_controller extends CI_Controller {
public function index()
{
$this->load->helper('url');
$this->load->helper('html');
$this->load->view('products.php');
}
}
And from index, I call it:
echo base_url('Products_controller/index');
OR
echo base_url('Products'); // I have in config/routes.php ---> $route['Products'] = "Products_controller/index";
Anyone can help me? What am I missing ?
Thanks.
Though .htaccess depends on hosting server sometimes but you can try with this and let us know. Replace your .htaccess code with the following code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?/$1
Thats it.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /NewWebsite/index.php [L]
</IfModule>
The above should work - make sure your .htaccess is inside the sub-directory you want to run from.
Also make sure that you don't have a conflicting .htaccess rule in the base directory.
And finally, I got a solution about this topic.It was not about a .htaccess problem, was a really dump and simple mistake.
In CodeIgniter, the name of the controllers and the name of the file
have to have exactly the same name. I have been defining my
controllers with the first letter capitalized and not in the file
name. And now it is everything ok !
Thank you guys.
I have a problem....I removed index.php from url...So ma route is :
$route['default_controller'] = "pages/show/index";
$route['photo'] = "pages/show/photo";
$config['base_url'] = 'http://localhost/blogCI/';
If I write in browser : localhost/blogCI/photo doesn't work, but if I write localhost/blogCI/index.php/photo it's work...
I have a .htaccess in root:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I use apache and mod rewrite is actived and in my config
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
Everything is normal but I don't understand where is the problem...Help me guys please!!!!!!!!!!!
Won't work in a subfolder.
Create virtual host if you need CI to be located in that folder or move it to www root.