简体   繁体   中英

Redirecting a Url in codeIgniter to a root folder

I have a folder structure like this in Code igniter : -

- www
    - CI
      - application
        - config
          - config.php
      - adminfolder
      - system
      - css
      - jss

And now i want to redirect the Url when the user goes to the controller : formhandler and action: login of url, http://localhost/CI/formhandler/login to this : http://localhost/CI/adminfolder How to do this ? Thanks in advance .

This can be done by using URL Helper of CodeIgniter.

This helper library should br loaded using the following code:

$this->load->helper('url');

To redirect you just need to call function as follow. Put this code inside your login method.

redirect('http://localhost/CI/adminfolder');

Reference code: http://dwij.co.in/redirect-to-url-in-codeigniter

assuming your base url is:

$config['base_url'] = "http://localhost/CI/";

it's simply to do:

redirect(site_url('adminfolder'),'',301/*here your redirect http code*/);

and be sure the folder is accessible via browser

I had same issue and fix it by updating my .htaccess file with the following code.

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

I found it from https://codeigniter.com/user_guide/general/urls.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM