Routes in CodeIgniter

3

I would like to know how to create routes in CodeIgniter. At the moment, all I can do is routes of type " www.site.com/index.php/page2 ".

I would like to create routes like " www.site.com/page2 "

I've tried using the CodeIgniter 3 documentation tutorial

" $ route ['page2'] = 'page_patcher2'; " in the route file and nothing ....

I think they're called magic routes in the Code community.

Would anyone help?

    
asked by anonymous 08.06.2018 / 14:19

1 answer

5

My version of codeigniter is older than the current one. then .... But follow the example:

change your htaccess to:

<IfModule mod_rewrite.c>

    RewriteEngine On

    # Remove /index/
    RewriteRule ^(.*)/index/?$ $1 [L,R=301]

    # Remove trailing slashes (prevents duplicate SEO issues)
    RewriteRule ^(.+)/$ $1 [L,R=301]

    # Removes access to the system folder by users.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

    # If not a file or directory, route everything to CI
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ index.php [L]
    # RewriteRule ^(.*)$ index.php/$1 [L] # This is an alternative

</IfModule>

In your config:

$config['base_url'] = "http://www.seusite.com/";
# or use $config['base_url'] = "";
$config['uri_protocol'] = "REQUEST_URI";
$config['index_page'] = '';

and in your Routes: ( link )

$route['default_controller'] = 'welcome';
$route['product/(:any)'] = "tuaconfig/action";
$route['404_override'] = "";

If your version is the current one, I've seen it in the current documentation ( link ) and following it: In the framework root:

application/
assets/
system/
.htaccess
index.php

Then change the application / config / config.php file:

  $config['index_page'] = "index.php";
    $config['index_page'] = "";
    
08.06.2018 / 14:52