base_url is not working in codeigniter 3.0.3

北城余情 提交于 2019-12-08 05:11:35

问题


I am using CodeIgniter 3.0.3, and I can't config base_url(). while I am setting the base_url in config.php file to $config['base_url'] = 'localhost/codeig303'; and when i print it then it prints localhost/codeig303/ but when i use it in href then it repeat the url like localhost/codeig303/localhost/codeig303/, and if I set it to $config['base_url'] = ''; then it returns http://::1/codeig303/.

but it was working in codeigniter 3.0.1 i was using before


回答1:


add http: before localhost , instead of

$config['base_url'] = 'localhost/codeig303';

add this

$config['base_url'] = 'http://localhost/codeig303/';



回答2:


Repeated time show the localhost/codeig303/localhost/codeig303/ URL

pls add http:// for front of localhost

like http://localhost/codeig303

If you apply this type, then working fine.




回答3:


use this :

 <a href = "<?php echo base_url(); ?>your/directory">Something</a>

also

 $config['base_url'] = 'localhost/codeig303';

should be:

 $config['base_url'] = 'http://localhost/codeig303/';



回答4:


In localhost keep base_url() empty. When you upload to live server then add base_url() as http://stackoverflow.com/.

.htaccess (outside application folder)

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Codeigniter URLs




回答5:


Add the following code to 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'] = '';

and Add <?php echo base_url(); ?>/'your file locations'

Hope this Answer your question..!



来源:https://stackoverflow.com/questions/34653906/base-url-is-not-working-in-codeigniter-3-0-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!