Routes in Codeigniter

Asked

Viewed 355 times

1

I would like to know how to create routes in Codeigniter.At the moment, all I can get are routes like this " www.site.com/index.php/pagina2 ".

I’d like to create routes like " www.site.com/pagina2 "

I have tried using the Codeigniter 3 documentation tutorial

" $route['pagina2'] = 'controlador_pagina2'; " in the route archive and nothing....

I think they’re called magical routes in the Code community.

Someone would know to help?

  • 1

    Possible duplicate: https://stackoverflow.com/questions/7618633/routes-in-codeigniter-automatically

  • Maybe this link can help you: http://www.universidadecodeigniter.com.br/rotas-no-codeigniter-do-inicio-ao-fim/

  • It is not duplicated, this topic is in American stackoverflow, this is PT. I’ve looked at this tutorial and done exactly the same, but it didn’t work no :/ !

1 answer

3


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 faith:

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

and on your Routes: (https://www.codeigniter.com/userguide2/general/routing.html)

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

If your version is the current one, I saw in the current documentation ( https://www.codeigniter.com/userguide3/general/urls.html )and following her : At the root of the framework:

application/
assets/
system/
.htaccess
index.php

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

  $config['index_page'] = "index.php";
    $config['index_page'] = "";
  • I will configure this way and soon return with the answer. Thanks in advance!

  • I made an edit by placing link so you can better understand by the explanation of the manual

  • It worked here,I’m giving a better study in the documentation. I was developing a system in Rails 5,everything ready. And I discovered later that the client’s hosting does not support Ruby and nothing makes him change his hosting. And I had to migrate to PHP overnight...

  • good... It will all work out. Success

Browser other questions tagged

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