Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 网站自动将URL更改为开发/生产服务器_Php_Apache_.htaccess_Codeigniter_Netbeans - Fatal编程技术网

Php 网站自动将URL更改为开发/生产服务器

Php 网站自动将URL更改为开发/生产服务器,php,apache,.htaccess,codeigniter,netbeans,Php,Apache,.htaccess,Codeigniter,Netbeans,我继承了一个webapp,我正试图用Xampp、Codeigniter和Netbeans在我的工作电脑上本地安装它 我已经成功地将项目导入netbeans,可以点击run按钮并在浏览器中打开它。然而,我有一些奇怪的行为,我真的不明白我做错了什么 index.php包含以下行: define('ENVIRONMENT', 'development'); 然后在codeigniter应用程序文件夹中有一个development文件夹,其中有一个config.php。这具有当前设置为指向dev服务器

我继承了一个webapp,我正试图用Xampp、Codeigniter和Netbeans在我的工作电脑上本地安装它

我已经成功地将项目导入netbeans,可以点击run按钮并在浏览器中打开它。然而,我有一些奇怪的行为,我真的不明白我做错了什么

index.php包含以下行:

define('ENVIRONMENT', 'development');
然后在codeigniter应用程序文件夹中有一个development文件夹,其中有一个config.php。这具有当前设置为指向dev服务器(“”)的base_url集

我更改了这一行,使其指向localhost上的xampp服务器,即

$config['base_url'] = $config['base_url']   = 'http://127.0.0.1/';
当我按下run按钮时,它看起来很快就会转到该服务器,然后立即被重定向到

存在一个.htaccess文件,该文件具有以下内容:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^http://exampleDevServer$ [NC]
RewriteRule ^(.*)$ http://exampleDevServer/$1 [L,R=301]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
我试过打开和关闭重写,但都没有效果


我希望发生的是,当我在本地开发时,它是从xampp服务器运行的,然后我可以将define更改为production(或其他),然后它指向写入位置。要解决此问题,我需要在上面更改什么?

您可以更改confi文件 文件:application/config/config.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');


$host = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : 'CLI';
$config['local_ip'] = array('localhost','127.0.0.1');

if($host != 'CLI') {
    if(in_array($host,$config['local_ip'])) {
        $config['base_url'] = '';
    } else {
        $config['base_url'] = 'YOUR_LIVE_URL';
    }
} else {
    if(CLI_ENVIRONMENT == 'local') {
        $config['base_url'] = '';
    } else {
        $config['base_url'] = 'YOUR_LIVE_URL';
    }
}
?>

您可以更改confi文件 文件:application/config/config.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');


$host = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : 'CLI';
$config['local_ip'] = array('localhost','127.0.0.1');

if($host != 'CLI') {
    if(in_array($host,$config['local_ip'])) {
        $config['base_url'] = '';
    } else {
        $config['base_url'] = 'YOUR_LIVE_URL';
    }
} else {
    if(CLI_ENVIRONMENT == 'local') {
        $config['base_url'] = '';
    } else {
        $config['base_url'] = 'YOUR_LIVE_URL';
    }
}
?>

我相信这可以归结为-是的。Firefox自动将我引导到它认为localhost应该去的地方,在本例中是开发服务器,而不是我的本地服务器

我还按照下面评论中的建议更改了我的htaccess文件

RewriteEngine on
#RewriteCond %{HTTP_HOST} !^http://exampleDevServer$ [NC]
#RewriteRule ^(.*)$ http://exampleDevServer/$1 [L,R=301]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

我相信这可以归结为-是的。Firefox自动将我引导到它认为localhost应该去的地方,在本例中是开发服务器,而不是我的本地服务器

我还按照下面评论中的建议更改了我的htaccess文件

RewriteEngine on
#RewriteCond %{HTTP_HOST} !^http://exampleDevServer$ [NC]
#RewriteRule ^(.*)$ http://exampleDevServer/$1 [L,R=301]
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

使用xdebug跟踪它…您是否检查了此
$\u服务器['HTTP\u HOST']
?在
行上的
重写引擎下方注释2行,清除浏览器缓存并重新测试。我认为这可能是Firefox中的缓存问题。我在localhost和127.0.0.1上得到了不同的结果。我重置了缓存并重置了所有更改,现在我得到了一个空白屏幕。我认为这实际上是一个进步和不同的问题。我知道firefox上安装了一个clear cache(清除缓存)按钮。哦,我也遵循了@anubhava的建议,使用xdebug对其进行了注释…您是否检查了此
$\u服务器['HTTP\u HOST']
?注释掉
行上的
重写引擎下方的2行,清除浏览器缓存并重新测试。我认为这可能是Firefox中的缓存问题。我在localhost和127.0.0.1上得到了不同的结果。我重置了缓存并重置了所有更改,现在我得到了一个空白屏幕。我认为这实际上是一个进步和不同的问题。我知道firefox上安装了一个clear cache(清除缓存)按钮,在评论方面我也遵循了@anubhava的建议