【问题标题】:base_url is not working in codeigniter 3.0.3base_url 在 codeigniter 3.0.3 中不起作用
【发布时间】:2016-04-11 18:28:48
【问题描述】:

我正在使用 CodeIgniter 3.0.3,但无法配置 base_url()。虽然我将config.php 文件中的base_url 设置为$config['base_url'] = 'localhost/codeig303'; 并且当我打印它时它会打印localhost/codeig303/ 但是当我在href 中使用它时它会重复像localhost/codeig303/localhost/codeig303/ 这样的url,如果我将其设置为$config['base_url'] = '';,然后返回http://::1/codeig303/

但它在我之前使用的 codeigniter 3.0.1 中工作

【问题讨论】:

  • 这个$config['base_url'] = 'http://localhost/your_project/';怎么样
  • 它适用于url,但现在它不知道控制器内部的功能。在我的控制器中,我有一个加载视图的函数,但它说在此服务器上找不到 URL 'project/controller/function'
  • 很可能是您在主目录上的 htaccess
  • 试试 $config['base_url'] = false
  • 感谢 wolfgang1983 现在可以使用了

标签: php codeigniter base-url


【解决方案1】:

localhost 之前添加http: , 而不是

$config['base_url'] = 'localhost/codeig303';

添加这个

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

【讨论】:

    【解决方案2】:

    重复时间显示localhost/codeig303/localhost/codeig303/ URL

    请在 localhost 前面添加 http://

    点赞http://localhost/codeig303

    如果你应用这种类型,那么工作正常。

    【讨论】:

      【解决方案3】:

      使用这个:

       <a href = "<?php echo base_url(); ?>your/directory">Something</a>
      

      还有

       $config['base_url'] = 'localhost/codeig303';
      

      应该是:

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

      【讨论】:

        【解决方案4】:

        在 localhost 中保持 base_url() 为空。当您上传到实时服务器时,将base_url() 添加为http://stackoverflow.com/

        .htaccess(应用程序文件夹外)

        RewriteEngine on
        RewriteCond $1 !^(index\.php|images|robots\.txt)
        RewriteRule ^(.*)$ /index.php/$1 [L]
        

        Codeigniter URLs

        【讨论】:

        • 加载网址助手
        • @barakataliforoz 你检查了吗??
        • 根据 v3.0.3 中的 CI documentation,“base_url”配置不应为空。
        • 您需要在实时服务器上将其设为空,假设您的网站是“www.something.com”,但如果有人使用“something.com”并且base_url 设置为www.something.com会有问题。 httphttps 也是如此,您还必须进行 301 重定向。
        • 当有 https 我有另一个答案。但我认为这不适合这个。无论如何@Dray
        【解决方案5】:

        将以下代码添加到config.php:

        if(ENVIRONMENT != 'production')
        $config['base_url'] = (is_https() ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
        else $config['base_url'] = '';
        

        并添加&lt;?php echo base_url(); ?&gt;/'your file locations'

        希望这个回答你的问题..!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-05-16
          • 2011-09-20
          • 2021-08-24
          • 1970-01-01
          • 2017-06-13
          相关资源
          最近更新 更多