doucan9079 2016-01-01 04:25
浏览 38

与www的Codeigniter基本网址问题

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

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

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

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" />

JS - ">

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

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 error

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.

  • 写回答

3条回答 默认 最新

  • dongyan3237 2016-01-01 05:11
    关注

    Change your base url from

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

    to

    $config['base_url'] = 'http://www.example.com/';

    Reason:www and non-www website url are considered as different website so it gives the error of

    Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin'

    Better way is the add code in htaccess to convert non-www to www.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ http://www\.%{HTTP_HOST}/$1 [L,R=301]
    

    Hope this explain the reason of change...

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类