dongyakui8675 2014-02-04 00:10
浏览 39
已采纳

Codeigniter始终在子域或子文件夹上加载默认控制器

I know that there are a lot of solutions for this problem. But i've tried a lot of difference aproaches and non of them help. Explanation of the problem: When i set my CI project on the host webserver in a subfolder or Subdomain it only loads the default controller. On local everything works fine.

  • I've tried setting the Uri Protocol from "AUTO" to "REQUEST_URI", didn't help
  • I've tried many different htaccess solutions, but didn't help
  • I've tried working on old-school index.php urls, didn't help
  • I've tried disabling all routes, didn't help

    EDIT things tried:

  • I've tried removing klanten from base url, like suggested. didn't help (suggested by @tomexsans)

My Settings:

$config['uri_protocol'] = "REQUEST_URI";  
$config['index_page'] = '';
$config['base_url']= 'http://www.mywebsite.nl/klanten';

or for the subdomain:

$config['base_url']= 'http://klanten.mywebsite.nl/';

My htaccess:

DirectoryIndex index.php
RewriteEngine on

RewriteCond $1 !^(index\.php|img|stylesheets|javascript)
RewriteCond $1 !^(index\.php|img|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA] 

I'm running on a php 5.3.15 with CI 2.1.2

Any ideas are welcome!

  • 写回答

2条回答 默认 最新

  • douba8758 2014-02-12 07:31
    关注

    I did something, that i don't like to do, to fix it. First of all, yes i tried update CI but this didn't do anything..

    So my solution for CI2.1.2 was the following:

    Core/URI.php :185

        $uri = $_SERVER['REQUEST_URI'];
        if (strpos($uri, $_SERVER['SCRIPT_NAME']) === 0)
        {
            if($_SERVER['REMOTE_ADDR'] == "127.0.0.1" || $_SERVER['REMOTE_ADDR'] == "::1")
            {
                $uri = substr($uri, strlen($_SERVER['SCRIPT_NAME']));
            }
            else
            {
                $uri = ltrim ($uri,'/');    
            }
    

    This was a working solution for me when i place the CI website in a Subdomain, When you place it in a subfolder the else should probably be like this:

    $uri = ltrim ($uri,'/subfolder/');
    

    I hope it helps anyone, if there is a better way to achieve this, please say so.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢