【问题标题】:url shortning in code in code ignitercodeigniter中代码中的url缩短
【发布时间】:2016-06-27 21:32:12
【问题描述】:

我的控制器`

class index extends CI_Controller {

  function __construct()
  {
    parent::__construct();
    $this->load->helper('html');
    $this->load->helper('url');
    $this->load->helper('form');
  }

public function index()
{
    $this->load->view('login');
}
`   public function home()
    {
        $this->load->view('header');
        $this->load->view('index');
        $this->load->view('footer');
    }
}

这个控制器中函数home的url是这个 http://localhost:88/mlmm/index.php/index/home

我希望这个网址是 http://localhost:88/mlmm/home

【问题讨论】:

    标签: codeigniter url-rewriting


    【解决方案1】:

    要从您的 URL 中删除 index.php,您需要在其中添加 .htaccess 文件和下面的代码。

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* index.php/$0 [PT,L]
    

    要制作像 http://localhost:88/mlmm/home 这样的网址,您需要在 config/routes.php 文件中提及路由

    $route['home'] = 'index/home';
    

    注意:您提到了控制器名称 index 并且在 codeigniter 中默认控制器的第一个方法也是 index 所以这可能会产生问题所以我建议使用不同的控制器名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 2011-06-13
      • 2013-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多