在codeigniter中设置基础URL [英] Set up the base url in codeigniter
问题描述
应用程序
- 网站
- 应用程序
-images
当我访问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.php
中的 $ config ['base_url']
更改为 $ config ['base_url'] =http://。$ _ SERVER [HTTP_HOST]。/;
现在我更新了我的图片源和其他库源文件,我删除了本地主机和我的目录文件夹的名称:
< img src =images / images.PNG>
< li class =>< a href =<?php echo base_url;? > /website/index.php/home/>主页< / a>< / li>
。它说没有找到对象。有人能帮助我吗?
在Config.php中
$ config ['base_url'] ='http:// localhost / Appsite / website /';
$ config ['index_page'] ='';
#如果在线网站
#$ config ['base_url'] ='http://stackoverflow.com/';
在 .htaccess
(外部应用程序文件夹) - 删除URL中的 index.php
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]
访问网址
< a href =<?php echo base_url();?> contollerName / methodName>点击此处< / a>
访问图片
< img src =<?php echo base_url();?> images / images.PNG>
$ b $ p < c>< link rel =stylesheettype =text / csshref =<?php echo base_url();?> assets / css / style.css/>
使用 base_url
加载来自autoload.php的URL助手
I have the directory structure like this in code igniter:
Appsite
-website
-application
-images
When I accessing the image in index.php I used:
<img src="http://localhost/Appsite/website/images/images.PNG"
And the href is:
<li class=""><a href="http://localhos/tAppsite/website/index.php/home/">Home</a></li>
I think it is not a good practice to include the http://localhost
when accessing the images or libraries in code igniter. So I tried to change the $config['base_url']
in config.php
to $config['base_url'] = "http://".$_SERVER["HTTP_HOST"]."/";
And now I update my image source and other library source I remove the localhost and the name of my directory folder:
<img src="images/images.PNG">
<li class=""><a href= <?php echo base_url;?> /website/index.php/home/">Home</a></li>
But I get errors. it says object not found. Can some help me?
In Config.php
$config['base_url'] = 'http://localhost/Appsite/website/';
$config['index_page'] = '';
# If online site
# $config['base_url'] = 'http://stackoverflow.com/';
In .htaccess
(outside application folder) - To remove index.php
in URL
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]
To accessing URL
<a href="<?php echo base_url();?>contollerName/methodName"> click here</a>
To access image
<img src="<?php echo base_url();?>images/images.PNG">
To access CSS
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>assets/css/style.css"/>
To use base_url
load URL helper from autoload.php
这篇关于在codeigniter中设置基础URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!