CodeIgniter - Friendly URL

2

I'm trying to use the CodeIgnoter framework. but I can not get past this:

http://localhost:8087/CodeIgniter/index.php/usuario/home

for this:

http://localhost:8087/CodeIgniter/usuario/home

It always appears:

The requested URL /CodeIgniter/usuario/home was not found on this server.

File Router:

$route['(:any)'] = 'usuario';
$route['default_controller'] = 'usuario/home';
    
asked by anonymous 18.09.2015 / 04:54

2 answers

1

To set up friendly URL in Codeigniter follow the steps below.

Note: These steps are not necessarily sequential.

  • In the ./sua_pasta_project/application/config/config.php files, change the following value of the index_page key of the $ config vector:
  • From:

    $config['index_page'] = 'index.php';
    

    To:

    $config['index_page'] = '';
    
  • If it does not exist, create the .htaccess file in the root of your project (your_project_folder / .htaccess) with the following content:
  • Content:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|images|robots\.txt)
    RewriteRule ^(.*)$ /index.php/$1 [L]
    
  • In the same config.php file change the base_url key value of the $ config;
  • To:

    $config['base_url'] = 'http://sua_url_projeto/';
    

    In your case it will probably be:

    $config['base_url'] = 'http://localhost:8087/CodeIgniter/';
    

    Remembering that you can access your project as well:

    http://localhost:8087/sua_pasta_projeto/index.php/controller/method_action
    

    How to:

    http://localhost:8087/sua_pasta_projeto/controller/method_action
    

    Also note that the route.php file is used to configure custom routes, not to set up Codeigniter's default friendly URL.

        
    07.10.2015 / 19:56
    3

    Change config.php

    $config['index_page'] = "index.php"
    

    for

    $config['index_page'] = ""
    

    Create or change .htaccess

    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
    
        
    18.09.2015 / 21:45