简体   繁体   English

Codeigniter:Base_url似乎不起作用

[英]Codeigniter: Base_url doesn't seem to be working

I have developed a simple site that fetches tweets from the Twitter public timeline, caches them for 60 seconds and so on. 我开发了一个简单的网站,可以从Twitter的公共时间轴获取推文,并将其缓存60秒,依此类推。 I have recently moved hosts from Hostgator to Mediatemple and my site was previously working fine on Hostgator. 我最近将主机从Hostgator移到了Mediatemple,以前我的网站在Hostgator上运行良好。

My application doesn't use a database connection, nor does it use any form of flat-file database either. 我的应用程序既不使用数据库连接,也不使用任何形式的平面文件数据库。 Tweets are cached in an XML file stored in the root directory, not that most of that is important. 推文被缓存在根目录中存储的XML文件中,但这并不是很重要。

The url helper is being included as can be seen below (this is my helpers line from autoload.php): $autoload['helper'] = array('url'); 如下所示可以包含url帮助器(这是来自autoload.php的帮助器行): $autoload['helper'] = array('url');

I have also removed my index.php file from the URL using .htaccess directives and once again this was previously working on Hostgator (see my .htaccess code below): 我还使用.htaccess指令从URL中删除了index.php文件,并且再次在Hostgator上运行过(请参见下面的.htaccess代码):

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

In my home.php view file which is in the views folder inside of application, I am using the function base_url() which was previously working on Hostgator inside of my view files and appending it a base href value in my header: <base href="<?php echo base_url(); ?>" /> 在应用程序内部views文件夹中的home.php视图文件中,我使用的是base_url()函数,该函数先前在Viewg内的Hostgator上运行,并将其附加在我的标头中: <base href="<?php echo base_url(); ?>" />

Here is what my base_url value looks like in the config.php file: 这是我的base_url值在config.php文件中的样子:

$config['base_url'] = "http://threetune.com/";

Although what appears to be happening is that the base_url is not to be seen at all. 尽管似乎正在发生,但根本看不到base_url。 It doesn't appear to be echoing out the value of base_url as it appears to be empty for some reason. 它似乎没有回显base_url的值,因为出于某种原因它似乎为空。

What makes things weirder is that I have a link in another view file called 'fetch.php' and for some reason it appears to be stripping out the value (XSS filtering is off): <a href="threetune/show"><img src="assets/images/cookie.jpg" /></a> The threetune/show part is not to be seen and I only see an empty href value like this <a href=""><img src="assets/images/cookie.jpg" /></a> 使事情变得奇怪的是,我在另一个名为'fetch.php'的视图文件中有一个链接,由于某种原因,它似乎正在剥离该值(XSS过滤已关闭): <a href="threetune/show"><img src="assets/images/cookie.jpg" /></a>看不见threetune / show部分,我只看到一个空的href值,例如<a href=""><img src="assets/images/cookie.jpg" /></a>

Can anyone possibly see anything wrong that I may have done, some kind of Mediatemple server limitation or PHP.ini flag that needs to be set? 谁能看到我可能做错的任何事情,某种Mediatemple服务器限制或需要设置的PHP.ini标志? Thank you and I hope I was descriptive enough. 谢谢,我希望我能描述得足够。

I am on the grid as well. 我也在网格上。 After re-reading your question and doing a little testing (it works for me), I think what's happening is you forgot to load the url helper. 重新阅读您的问题并进行了一些测试(对我有用)后,我认为您正在忘记加载url帮助程序。

If you want the sites base url available to you to use in the application via base_url() , you need to load the url helper first. 如果希望通过base_url()在应用程序中使用网站的基本URL,则需要先加载url帮助器。 Either via config/autoload.php or load it manually in your controller. 通过config / autoload.php或将其手动加载到控制器中。

Otherwise you could use config/constants.php to define constant variables: 否则,您可以使用config / constants.php定义常量变量:

define('BASE_URL', 'http://site.com');
define('BASE_PATH', '/path/to/CI/folder');

Just a quick note on base_url - might be a good idea to dynamically set this variable, as it will allow your site to support multiple domains. 简要介绍一下base_url-动态设置此变量可能是个好主意,因为它将允许您的站点支持多个域。

(i.e. $config['base_url']    = ‘http://’.$_SERVER['HTTP_HOST'])

http://thecodeabode.blogspot.com/2010/10/codeigniter-supporting-multiple-domains.html expands a bit on this by giving scripts that take into consideration protocol and port. http://thecodeabode.blogspot.com/2010/10/codeigniter-supporting-multiple-domains.html通过提供考虑协议和端口的脚本,对此进行了扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM