Search code examples
php.htaccesscodeigniterweb-hostinghtdocs

Codeigniter server error when the URL contains any controller or method with arguments on a hosting service


I did develop my website on localhost using codeigniter framework then I got a domain name and hosting service from www.web.com.

I upload my website to folder htdocs in root folder of the server. This is the structure:

  • /
    • cgi-bin
    • htdocs
      • application
      • system
      • js
      • css
      • img
      • index.php
      • .htaccess

suppose that my domain is www.example.com and it is pointing to htdocs folder.

When I type www.example.com it opens my home page successfully without errors.

But when I try to open any other page such www.example.com/products or www.example.com/products/browse_product/2 it loads the page successfully but at the end of every page this error always appears

ERROR SCREENSHOT

My .htaccess file :

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

Solution

  • I did solve the problem by performing this:

    /* config.php file */

    $config['index_page'] = ''; 
    $config['uri_protocol'] = 'REQUEST_URI';
    

    /* routes.php file */

    $route['default_controller'] = "home"; 
    $route[''] = "home/index"; 
    $route['home'] = "home/index"; 
    $route['404_override'] = ''; 
    

    /* main .htaccess file */

    <IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteBase / 
    RewriteRule ^index\.php$ - [L] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule . /index.php [L] 
    </IfModule>