在codeigniter中设置基本URL

qaz*_*zzu 5 html php codeigniter base-url codeigniter-2

我在代码点火器中有这样的目录结构:

 Appsite
    -website
       -application
        -images
Run Code Online (Sandbox Code Playgroud)

当我在index.php中访问图像时,我使用了: <img src="http://localhost/Appsite/website/images/images.PNG"

并且href是: <li class=""><a href="http://localhos/tAppsite/website/index.php/home/">Home</a></li>

我认为http://localhost在代码点火器中访问图像或库时包含它并不是一个好习惯.所以我试着将$config['base_url'] in config.php 改为$config['base_url'] = "http://".$_SERVER["HTTP_HOST"]."/";

现在我更新了我的图像源和其他库源我删除了localhost和我的目录文件夹的名称:

<img src="images/images.PNG”> <li class=""><a href= <?php echo base_url;?> /website/index.php/home/">Home</a></li>

但我得到错误.它说没找到物体.有人可以帮帮我吗?

Abd*_*lam 10

在Config.php中

$config['base_url'] = 'http://localhost/Appsite/website/';
$config['index_page'] = '';

# If online site
# $config['base_url'] = 'http://stackoverflow.com/';
Run Code Online (Sandbox Code Playgroud)

.htaccess(外部应用程序文件夹) - 要删除index.phpURL

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|image|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)

访问URL

<a href="<?php echo base_url();?>contollerName/methodName"> click here</a>
Run Code Online (Sandbox Code Playgroud)

访问图像

<img src="<?php echo base_url();?>images/images.PNG”>
Run Code Online (Sandbox Code Playgroud)

访问CSS

<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/css/style.css"/>
Run Code Online (Sandbox Code Playgroud)

使用base_urlautoload.php中的加载URL帮助程序