2012-08-03 54 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;