[英]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.