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 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?