2016-08-12 62 views
1

我已經繼承了一個Web應用程序,我試圖在我的工作電腦上使用Xampp,Codeigniter & Netbeans在本地進行設置。網站自動更改URL到開發/生產服務器

我已經成功將項目導入到NetBeans中,並可以運行按鈕並在瀏覽器中打開。不過,我有一些奇怪的行爲,我不明白我做錯了什麼。

在index.php具有行:

define('ENVIRONMENT', 'development'); 

然後笨應用程序文件夾內有其具有的config.php顯影文件夾。這有其目前正在開發服務器設置爲點BASE_URL集(「http://exampleDevServer」)

$config['base_url'] = 'http://exampleDevServer"'; 

,使其指向localhost上XAMPP服務器我已經改變了這條線,即

$config['base_url'] = $config['base_url'] = 'http://127.0.0.1/'; 

當我按下運行按鈕時,它看起來像是輕輕地進入該服務器,然後立即被重定向到http://exampleDevServer

有它具有以下.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服務器運行,然後我可以將定義更改爲生產(或其他),然後它指向寫入位置。爲了解決這個問題,我需要改變什麼?

+0

用xdebug跟蹤它... – obe

+0

你檢查了這個'$ _SERVER ['HTTP_HOST']'嗎? – devpro

+0

版本的CI? – jagad89

回答

0

我相信這可以歸結爲http://shouldiblamecaching.com/ - 是的。通過Firefox自動將我指向本地主機應該訪問的內容,在本例中是dev服務器而不是本地服務器。

我也改變了我的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] 
0

你可以改變你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'; 
    } 
} 
?> 
相關問題