Codeigniter - URL friendly

Asked

Viewed 3,721 times

2

I’m trying to use the Codeignoter framework.
but I’m not getting past it:

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

for that reason:

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

Always appears :

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

File router:

$route['(:any)'] = 'usuario';
$route['default_controller'] = 'usuario/home';
  • In the config.php file you have already taken the index php. of $config['index_page'] = '';. also checks the file .htaccess

2 answers

3

Change the 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] 
  • Mine’s like that too and works perfectly...

1


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

Note: These steps are not necessarily sequential.

  1. In the files . /sua_pasta_projeto/application/config/config.php change the following value of the $config vector index_page:

Of:

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

To:

$config['index_page'] = '';
  1. If not, create the . htaccess file at the root of your project (sua_pasta_project/.htaccess) with the following contents:

Contents:

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

To:

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

In your case you’ll probably stay:

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

Remembering that you will be able to access your project so much:

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

Like:

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

Remember also that the route.php file serves to configure custom routes, not to configure the default Codeigniter friendly URL.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.