base_url 形式的 CodeIgniter 问题

CodeIgniter issue with base_url in form

我在本地计算机的视图中的表单操作中调用了 base_url()。但是,它将 url 作为 http://::1/codeigniter/ 而不是 http://localhost/codeignitersite_url()也是如此。

.htaccess文件的问题还是我应该在config.php中进行任何设置?

下面是我的 .htaccess 文件:

DirectoryIndex index.php
RewriteEngine on

RewriteCond  !^(index\.php|(.*)\.swf|forums|images|css|downloads|jquery|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php? [L,QSA]

我使用的是 CodeIgniter 3.0 版本。

如果您将其留空,自 2.0.0 版起,框架将尝试自动检测它。尝试在配置中设置该值:$config['base_url'] = 'http://localhost/codeigniter/' 我认为一切正常。

编辑:带尾部斜杠。

如果您不想更改 $config['base_url'],在更改服务器或将项目从本地机器移动到实时服务器时,试试这个:

$root = "http://".$_SERVER['HTTP_HOST'];
$root .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
$config['base_url']    = "$root";

This can possibly avoid all issues with $config['base_url'] .