问题
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