Codeigniter基本URL问题与www [英] Codeigniter base url issue with www

查看:143
本文介绍了Codeigniter基本URL问题与www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将基本网址声明为$ config ['base_url'] =' http://example.com/

I have declared the base url as $config['base_url'] = 'http://example.com/';.

但问题是如果有人尝试访问我的网站时使用 http://www.example.com/ '; ,css / js函数不工作。

But the issue is if someone try to access my website with 'http://www.example.com/'; , css/ js functions are not working.

如果我将基本网址更改为 http:// www .example.com / ,用户无法使用 http://example.com/ 访问。

If I change the base url to 'http://www.example.com/' , users cannot access with 'http://example.com/'.

我使用codeigniter 3.0.3。这是已在线的网站的问题。

I am using codeigniter 3.0.3 . This is an issue with a website which is already online.

CSS - assets / plugins / bootstrap / css / bootstrap.min.css/>

CSS - assets/plugins/bootstrap/css/bootstrap.min.css" />

JS - >

。 btw,ajax请求也失败。当我尝试访问ajax函数时,控制台上显示的下面的错误 -

. btw , ajax request are also failed.When I try to access an ajax function the bellow error showing on console –

XMLHttpRequest无法加载 http://www.example.com/Dynamic/home/normal/4 。在所请求的资源上没有Access-Control-Allow-Origin头。原因 http://example.com 因此不允许访问。

XMLHttpRequest cannot load http://www.example.com/Dynamic/home/normal/4. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access.

css错误

源自 http:// www.example.com 已被跨源资源共享策略阻止加载:在请求的资源上没有访问控制允许来源标头。因此,原始' http://example.com '不允许访问。

Font from origin 'http://www.example.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com' is therefore not allowed access.

推荐答案

我认为以下代码块显示了在Codeigniter中配置base_url的最佳方法:

I think the following code-block shows the best way to configure the base_url in Codeigniter :

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

我坚信这会解决你的问题。谢谢。

And I strongly believe that this will solve your problem. Thank you.

这篇关于Codeigniter基本URL问题与www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆