Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.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 如何设置正确的codeigniter基url?_Php_Codeigniter - Fatal编程技术网

Php 如何设置正确的codeigniter基url?

Php 如何设置正确的codeigniter基url?,php,codeigniter,Php,Codeigniter,当我把我的网站放在开发环境中时,它是url:testurl.com 现在,在生产服务器上,我的codeigniter应用程序的地址必须是someurl.com/mysite/ 我把它移到了那里,每次我试着运行一些函数,例如/home/test-它让我进入someurl.com/home/test-这是错误的 它必须是someurl.com/mysite/home/test-如何修复?我定了 $config['base_url'] = someurl.com/mysite/ 如果将其保留为空,框

当我把我的网站放在开发环境中时,它是url:testurl.com

现在,在生产服务器上,我的codeigniter应用程序的地址必须是someurl.com/mysite/

我把它移到了那里,每次我试着运行一些函数,例如/home/test-它让我进入someurl.com/home/test-这是错误的

它必须是someurl.com/mysite/home/test-如何修复?我定了

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

如果将其保留为空,框架将尝试从版本
2.0.0
开始对其进行修改


但不是在
3.0.0
中,请参见此处:

也尝试将控制器添加到索引页。只是在我自己的一个网站上看到了类似的结构,我将我的基本url设置为=“somedomain.com/v2/controller”

是否缺少双引号

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


基本URL应为绝对URL,包括协议:

$config['base_url'] = "http://somesite.com/somedir/";
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/mysite/";
如果使用URL帮助器,则
base\u URL()
将输出上述字符串

将参数传递给
base\u url()
site\u url()
将导致以下结果(假设
$config['index\u 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

在config.php中声明基本url后,(注意,如果仍然出现相同的错误,请检查autoload.php)

选中“自动加载”

CodeIgniter文件结构:

\application\config\autoload.php
并在自动加载时启用:

$autoload['helper'] = array(**'url',** 'file');
$autoload['helper'] = array('url','file');
而且它可以工作。

检查

配置>配置

codeigniter文件结构

替换

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


您可以为任何服务器使用默认的基本URL路径 必须在config folder>config.php文件中使用的 替换您:

$config['base_url'] = 'index.php';
根据该守则:
$config['base\u url']=“http://”$\u服务器['http\u主机];
$config['base\u url'].=preg\u replace('@/+$@','',dirname($\u SERVER['SCRIPT\u NAME'])。/';


它可以从任何服务器自动找到您的文件夹

这很有趣,下面是快速有效的代码:

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'])); 
/*
|--------------------------------------------------------------------------
| 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;
defined('BASE_URL') OR define('BASE_URL', (is_https() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/');
$config['base_url'] = BASE_URL;
config.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'])); 
/*
|--------------------------------------------------------------------------
| 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;
defined('BASE_URL') OR define('BASE_URL', (is_https() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/');
$config['base_url'] = BASE_URL;
代码点火器岩石!!!:)

动态基本Url(codeigniter)

只需使用以下内容覆盖config/config.php中的行:

$config['base_url']='http://'。$\u SERVER['http_HOST'].//'

通过这种方式,您可以配置您的基本url,这样就不必担心托管中的问题。两者都在本地主机和服务器中工作


应用程序>配置>config.php

搜索$config['base_url'],然后像“//example.com”(跳过协议)一样放置您的站点


这对我很有用。

这是我在hostinger.com上申请的服务器nd live站点,它工作正常

第一:
$config['base\u url']='http://yoursitename.com';(在confing.php中)

2) :
src=“assest/js/wow.min.js”
(在视图文件中)


3) :
href=“index.php/Mycontroller/Method”
(用于url链接或方法调用)

像这样更改config.php

$base_url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$base_url .= "://". @$_SERVER['HTTP_HOST'];
$base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url'] = $base_url;

基本URL应为绝对URL,包括协议:

$config['base_url'] = "http://somesite.com/somedir/";
$config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/mysite/";
此配置将在本地主机和服务器中工作

不要忘记在自动加载时启用:

$autoload['helper'] = array(**'url',** 'file');
$autoload['helper'] = array('url','file');
然后base_url()将输出如下

echo base_url('assets/style.css'); //http://yoursite.com/mysite/assets/style.css

我认为CodeIgniter 3建议手动将
$config['base\u url']
设置为完整url,以避免错误

如果您不关心它,只需在

application/config/config.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'])); 
/*
|--------------------------------------------------------------------------
| 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;
defined('BASE_URL') OR define('BASE_URL', (is_https() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']) . '/');
$config['base_url'] = BASE_URL;
这样,您的所有项目代码(包括视图)中都有可用的
BASE\u URL
常量,您不必使用以下函数:

config_item('base_url') //returns BASE_URL
$this->config->item('base_url'); //returns BASE_URL

在配置文件中,保留
$config['base\u url']=''

base\u url
将自动创建一个。在Codeigniter
system/core/Config.php中

//如果未提供基本url,则自动设置该url
if(空($this->config['base\u url']))
{
如果(isset($\u SERVER['SERVER\u ADDR']))
{
if(strpos($_SERVER['SERVER\u ADDR'],':')!==FALSE)
{
$server\u addr='['.$\u server['server\u addr'].]';
}
其他的
{
$server\u addr=$\u server['server\u addr'];
}
$base_url=(是_https()?'https':'http')。:/'。$server\u addr
.substr($_服务器['SCRIPT\u NAME'],0,strpos($_服务器['SCRIPT\u NAME'],basename($_服务器['SCRIPT\u FILENAME'])));
}
其他的
{
$base\u url='1http://localhost/';
}
$this->set_项($base_url',$base_url);
}
此代码已经存在,可以自动创建基本URL和协议


谢谢。

请你再详细解释一下好吗?据我所知,你的应用程序和系统文件夹位于一个名为“mysite”的文件夹中,据说我在自己的一个网站上有一个类似的结构。其中,我已将我的基本url设置为“”,其中v2是我的“mysite”文件夹版本,控制器(或控制器/函数)是您希望用作索引页的控制器。我设置了,但更改没有帮助:)+1获取您关于绝对引用的答案。。。但是看看这个,我有一个疑问。。。将CodeIgniter文件和“somesite”文件放在同一位置(即www)不是一个坏主意吗?我的意思是这不会让外部机器人可以访问CodeIgniter文件吗?只是好奇……可能是的,有两件事需要考虑:1)如果(!defined('BASEPATH'))退出('No direct script access allowed'),所有CI项目文件都应该有
作为第一行。这会阻止脚本自身运行,因为没有以其他方式定义
BASEPATH
常量(无论是CI的前端控制器还是其他脚本)。2) 您可以安全地移动
系统
应用程序
文件夹