简体   繁体   English

将 codeIgniter 中的 Url 重定向到根文件夹

[英]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 ?现在我想在用户转到控制器时重定向 Url:formhandler 和操作:url 登录, http://localhost/CI/formhandler/login到这个: http://localhost/CI/adminfolder怎么做这 ? Thanks in advance .提前致谢 。

This can be done by using URL Helper of CodeIgniter.这可以通过使用 CodeIgniter 的 URL Helper 来完成。

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参考代码: 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.我遇到了同样的问题,并通过使用以下代码更新我的 .htaccess 文件来修复它。

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我从https://codeigniter.com/user_guide/general/urls.html找到它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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