如何设置正确的codeigniter基地url?
当我有我的网站在开发环境 – 这是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应该是绝对的,包括协议:
 $config['base_url'] = "http://somesite.com/somedir/"; 
 如果使用URL助手,则base_url()将输出上面的string。 
 将parameter passing给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 
检查
config> config
codeigniter文件结构
更换
 $config['base_url'] = "your Website url"; 
同
 $config['base_url'] = "http://".$_SERVER['HTTP_HOST']; $config['base_url'] .= preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_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'])); 
 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; 
CodeIgniter岩石! 🙂
 如果将其留空,则框架将尝试从版本2.0.0开始自动检测它。 
 但不是在3.0.0 ,请看这里: config.php 
在config.php中声明基本URL后(注意,如果你仍然得到相同的错误,请检查autoload.php)
 $config['base_url'] = "http://somesite.com/somedir/"; 
检查“自动加载”
CodeIgniter文件结构:
 \application\config\autoload.php 
并启用自动载入:
 $autoload['helper'] = array(**'url',** 'file'); 
它工作。
应用程序>configuration> config.php
search$ config ['base_url'],并把你的网站像“//example.com”(跳过协议)
  $config['base_url'] = "//someurl.com/"; 
这对我有用。
这是服务器nd现场我申请hostinger.com和它的工作正常
  1st: $config['base_url'] = 'http://yoursitename.com'; http: $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链接或方法调用) 
dynamic基地址(codeigniter)
只需使用以下命令覆盖config / config.php中的行:
$ config ['base_url'] ='http://'.$_SERVER ['HTTP_HOST']。'/';
 $config['base_url'] = "http://".$_SERVER['SERVER_NAME']."/project_name/"; 
这样你configuration你的base_url,然后不会担心在托pipe。 都在本地主机和服务器上运行。
 Base url set in CodeIgniter for all url $config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/"; 
你想念双引号吗?
$ config ['base_url'] =“someurl.com/mysite”
你可以使用默认的基本urlpath的任何服务器必须使用在config文件夹> config.php文件取代你—>
 $config['base_url'] = 'index.php'; 
 通过以下代码: $config['base_url'] = "http://".$_SERVER['HTTP_HOST']; $config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/'; $config['base_url'] = "http://".$_SERVER['HTTP_HOST']; $config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/'; 
它是自动find你的文件夹forms的任何服务器
尝试将控制器添加到您的索引页面。 刚刚在我自己的网站上看到类似的结构,我把我的基地url设置为=“somedomain.com/v2/controller”