doulu1867 2014-12-29 18:03
浏览 49
已采纳

CodeIgniter RESTful可脱机工作,但不能在线工作

I believe the reason why I have this problem is because of .htaccess (although they are the same in offline and online).

http://localhost/myProject/api/webservice/getUsers -> Works
http://myProjectDomain.com/api/webservice/getUsers -> Doesn't work, error: 500 Internal Error

.htaccess from root folder:

Options -Indexes
Options +FollowSymLinks

# Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>

    # activate URL rewriting
    RewriteEngine on

    # do not rewrite links to the documentation, assets and public files
    RewriteCond $1 !^(index\.php|public|images|robots\.txt)

    # do not rewrite for php files in the document root, robots.txt or the maintenance page
    RewriteCond $1 !^([^\..]+\.php|robots\.txt)

    # but rewrite everything else
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>

    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.

    ErrorDocument 404 index.php

</IfModule> 

In my point of view I might need to create another rule? Something like:

RewriteRule ^(.*)$ index.php?/api/webservice/$1 [L]
  • 写回答

1条回答 默认 最新

  • dongmu1914 2014-12-29 18:22
    关注

    Solved.

    I found my answer in this topic: malformed header from script. Bad header=1: index.php

    A few weeks ago I had to changed my REST_controller.php file in order to receive large amount of data from the webservice. Although I found a little bug, when the amount of data was too big, it wouldn't retrieve it completely.

    For example, the format JSON.

    [{data: {'values': '1'}, {'values': '2'}]
    

    Now this is large scale only retrieves me:

    [{data: {'values': '1'}, {'values': '2'
    

    Yes, it misses the }], therefore the JSON format wasn't good. So i've change a little the code, from:

    header('Content-Length: ' . strlen($output));
    

    to:

    header('Content-Length: ' . strlen($output) + 15);
    

    But I made a basic mistake that I wouldn't do if I was coding in a typed language. The values weren't actually summed but concatenated. Solution:

    header('Content-Length: ' . (strlen($output) + 15));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数