2012-08-03 35 views
26

當我有我的開發環境中的網站 - 這是網址:testurl.com如何設置正確的codeigniter基礎url?

現在生產服務器上我笨的應用程序的地址必須someurl.com/mysite/

我把它那裏,每次我試圖運行一些功能,例如/home/test - 它讓我進入someurl.com/home/test - 這是錯誤的。

它必須是someurl.com/mysite/home/test - 如何解決它?我沒有設定

$config['base_url'] = someurl.com/mysite/ 

回答

52

基本URL應該是絕對的,包括協議:

$config['base_url'] = "http://somesite.com/somedir/"; 

如果使用URL幫手,那麼base_url()會輸出上面的字符串。

將參數傳遞給base_url()site_url()會導致以下(假設$config['index_page'] = "index.php";

echo base_url('assets/stylesheet.css'); // http://somesite.com/somedir/assets/stylesheet.css 
echo site_url('mycontroller/mymethod'); // http://somesite.com/somedir/index.php/mycontroller/mymethod 
+0

+1爲您的絕對參考答案...但看着這個,我有疑問...是不是一個壞主意CodeIgniter文件和'somesite'文件在相同的位置(即www)?我的意思是這不會使外部機器人使用CodeIgniter文件加速嗎?只是好奇... – itsols 2013-01-16 10:05:13

+3

潛在的,是的,有需要考慮兩件事情:1)所有的CI項目文件應該有'如果(定義(「基本路徑」!))退出()「允許無直接腳本訪問」;'作爲第一行。這可以防止腳本本身運行,因爲'BASEPATH'常量沒有另外定義(無論是CI的前端控制器還是其他腳本)。 2)只要您在CI的前端控制器(index.php)中指定了它們的路徑,就可以安全地將'system'和'application'文件夾移動到webroot(www,就你的案例而言)之外。基本上你的webroot只會包含index.php和assets。希望有所幫助。 – Brendan 2013-01-16 17:20:52

+0

什麼是overiding此的baseUrl – 2017-06-21 12:54:38

-2

嘗試將控制器添加到您的索引頁以及。剛剛在我自己的網站上看到類似的結構,我把我的基礎url設置爲=「somedomain.com/v2/controller」

+0

請問您能更深一點解釋一下嗎? – pawel 2012-08-03 08:52:59

+0

據我瞭解,你的應用程序和系統文件夾位於一個名爲「mysite」的文件夾中,正如我說的,我在自己的網站上有一個類似的結構。在哪裏我已經設置我的基地網址爲「http://www.somedomain.com/v2/controller」,其中v2是我的版本的「mysite」文件夾和控制器(或控制器/功能)是您想要的控制器有作爲您的索引頁面。 – pbappia12 2012-08-03 08:57:09

-1

你想念雙引號嗎?

$配置[ 'BASE_URL'] = 「someurl.com/mysite」

+0

我這樣做,但改變並沒有幫助:) – pawel 2012-08-03 09:09:04

2

聲明基本URL在config.php,(注後,如果您仍然得到同樣的錯誤,檢查自動加載.PHP)

$config['base_url'] = "http://somesite.com/somedir/"; 

選中 「自動加載」

CodeIgniter的文件結構:

\application\config\autoload.php 

,並開啓自動加載:

$autoload['helper'] = array(**'url',** 'file'); 

和它的作品。

17

檢查

配置>配置

笨文件結構

更換

$config['base_url'] = "your Website url"; 

$config['base_url'] = "http://".$_SERVER['HTTP_HOST']; 

$config['base_url'] .= preg_replace('@/[email protected]', '', dirname($_SERVER['SCRIPT_NAME'])).'/'; 
0

你可以使用默認的基本URL路徑的任何服務器 已在config文件夾所用>的config.php文件 代替你:此代碼

$config['base_url'] = 'index.php'; 

$config['base_url'] = "http://".$_SERVER['HTTP_HOST']; $config['base_url'] .= preg_replace('@/[email protected]','',dirname($_SERVER['SCRIPT_NAME'])).'/';

它的汽車發現你的文件夾形式的任何服務器

5

這是非常有趣的,這裏是快速和工作代碼:

index.php

/** 
* Define APP_URL Dynamically 
* Write this at the bottom of index.php 
* 
* Automatic base url 
*/ 
define('APP_URL', ($_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http') . "://{$_SERVER['SERVER_NAME']}".str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME'])); 

config.php

/* 
|-------------------------------------------------------------------------- 
| Base Site URL 
|-------------------------------------------------------------------------- 
| 
| URL to your CodeIgniter root. Typically this will be your base URL, 
| WITH a trailing slash: 
| 
| http://example.com/ 
| 
| If this is not set then CodeIgniter will guess the protocol, domain and 
| path to your installation. 
| 
*/ 
$config['base_url'] = APP_URL; 

笨ROCKS! :)

+0

它與動態子領域的作品以及場景? – WebDevRon 2016-09-11 13:31:53

+0

@WebDevRon:是的! – 2016-09-13 03:14:16

0

動態基地址(笨)

只是覆蓋在配置/ config.php文件中的符合以下:

$配置[ 'BASE_URL'] =的「http:/ /'.$_SERVER['HTTP_HOST'].'/';

+0

如果http://www.spisstek.com/,然後http://spisstek.com/。 兩個URL它工作正常...我將用它在我的網站上..鏈接在這裏... – 2016-07-02 09:15:35

0
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/project_name/"; 

這種方式,您的配置您BASE_URL,那麼就不會在託管擔心。這兩個工作在本地主機和服務器。

+0

如果你需要的index.php在URL添加它你的項目name.to刪除的index.php u需要後在confiq頁面中更改.htaccess和更改 – 2017-03-02 05:10:18

0
Base url set in CodeIgniter for all url 

$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/"; 
1

應用程序>配置> config.php文件

搜索$配置[ 'BASE_URL'],並把你的網站,如 「//示例.com」(跳過協議)

$config['base_url'] = "//someurl.com/"; 

這適用於我。

1

這是我在應用服務器hostinger.com第二直播網站和其工作的罰款

1:$config['base_url'] = 'http://yoursitename.com';(在confing。PHP)

2):src="<?=base_url()?>assest/js/wow.min.js"(以查看文件)

3):href="<?php echo base_url()?>index.php/Mycontroller/Method"(對於URL鏈接或方法調用)

0

變化這樣的config.php。

$ark_root = "http://".$_SERVER['HTTP_HOST']; 
$ark_root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']); 
$config['base_url'] = $ark_root;