[英]base_url is not working in codeigniter 3.0.3
我正在使用 CodeIgniter 3.0.3,但无法配置base_url()
。 当我将config.php
文件中的base_url
设置为$config['base_url'] = 'localhost/codeig303';
当我打印它时,它会打印localhost/codeig303/
但是当我在href
中使用它时,它会重复localhost/codeig303/localhost/codeig303/
之类的 url,如果我将它设置为$config['base_url'] = '';
然后它返回http://::1/codeig303/
。
但它在我之前使用的 codeigniter 3.0.1 中工作
在localhost
之前添加http:
,而不是
$config['base_url'] = 'localhost/codeig303';
添加这个
$config['base_url'] = 'http://localhost/codeig303/';
重复时间显示 localhost/codeig303/localhost/codeig303/ URL
请在 localhost 前面添加 http://
如果你应用这种类型,那么工作正常。
用这个 :
<a href = "<?php echo base_url(); ?>your/directory">Something</a>
还
$config['base_url'] = 'localhost/codeig303';
应该:
$config['base_url'] = 'http://localhost/codeig303/';
在 localhost 中保持base_url()
为空。 当您上传到实时服务器时,将base_url()
添加为http://stackoverflow.com/
。
.htaccess (应用程序文件夹外)
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
将以下代码添加到 config.php:
if(ENVIRONMENT != 'production')
$config['base_url'] = (is_https() ? 'https' : 'http').'://'.$_SERVER['HTTP_HOST'].substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
else $config['base_url'] = '';
并添加<?php echo base_url(); ?>/'your file locations'
<?php echo base_url(); ?>/'your file locations'
希望这回答你的问题..!
将以下代码添加到 autoload.php:
$autoload['helper'] = array('url');
我希望这回答了你的问题!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.