Redirect with or without bar (/) slash at the end in Codeigniter

0

I use the codeigniter framework for development, the problem is that I have the following url http://localhost:8080/proyecto/index.php/home/ , with this url everything works from 'wonder' everything is loaded correctly, but if I use this url http://localhost:8080/proyecto/index.php/home if I remove the against slash of the home / the page is loaded but the data is lost, then the idea is that when that slash is removed, redirecting it http://localhost:8080/proyecto/index.php/home/ ..

this is the function:

public function index()
    {
        if($this->session->userdata('login'))
        {
            $this->load->view('home');
        }
        else
        {
            redirect(site_url());
        }
    }

I would appreciate your collaboration ...

    
asked by JDavid 13.03.2017 в 14:37
source

1 answer

1

To do what you ask to create a .htaccess file in the project root:

With the following code:

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

This to get friendly URLs. I recommend that you activate the mod_rewrite of your file httpd.conf decomentando the following line:

LoadModule rewrite_module modules/mod_rewrite.so

In this way you avoid the index.php of your URL, leaving URLs as follows:

http://localhost:8080/proyecto/home
    
answered by 13.03.2017 / 16:05
source