Codeigniter base_url() 将 index.php 添加到我的路径

Codeigniter base_url() adds index.php to my path

我有这段代码,我想将样式表文件添加到我的 CI 项目中的页面。我已将配置文件设置为

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

但是,试图获取此文件的 link 包含 index.php 并且在 return 中我无法 link 样式表。我的代码有什么问题?

<link href="../<?php base_url();?>vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">

当我回显基数 url 时,它显示 localhost/project/.

这是错误:GET http://localhost/project/index.php/vendor/bootstrap/css/bootstrap.min.css 404(未找到)

作为您的问题

的一个非常先进的解决方案

1- 您必须将 .htaccess 文件设置为:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/ [L]

2- 将 config.php 文件夹中的 config 文件设置为:

$url = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$url .= "://".$_SERVER['HTTP_HOST'];
$url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

$config['base_url'] = $url;

$config['index_page'] = '';

有了这个技巧,你甚至不需要手动设置 $config['base_url'] :)

$config['base_url'] 需要完整的 URL 协议。试试这个。

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

如果您使用的是 ssl,则协议应为 https://