dongli1920 2013-01-22 13:50
浏览 178
已采纳

找不到resources.json

For some reason when I deploy my API using Restler's API Explorer (a fork of Swagger UI) to production it gives me a general 404 error when I load:

/api/explorer

When I am more explicit and state:

/api/explorer/index.html

It loads the framing for the page but then reports "404 : Not Found ../resources.json" in red text below the header:

enter image description here

I'm fairly certain there's something environmental flaring up as the same files locally work. I also checked the .htaccess file in the /api/explorer directory and it looks right to me:

DirectoryIndex index.php
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^$ index.html [QSA,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>

Any help would be appreciated.

  • 写回答

4条回答 默认 最新

  • dongqixuan3112 2013-02-11 17:37
    关注

    It turns out all the problems were down to a mod_rewrite problem. I'm still not 100% on WHY this problem showed up in one environment but not others with precisely the same httpd.conf and .htaccess. Oh well, the solution is to be explicit in the rewrite rule about your base url using the RewriteBase directive.

    In the API directory I now have the following .htaccess file:

    DirectoryIndex index.php
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /api
        RewriteRule ^$ index.php [QSA,L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
    

    In the API-Explorer directory I now have the following .htaccess:

    DirectoryIndex index.php
    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /api/explorer
        RewriteRule ^$ index.html [QSA,L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.html [QSA,L]
    </IfModule>
    

    In order to troubleshoot this problem one invaluable tip that I came across is turning on Apache's mod_rewrite logging.

    # Adding logging for Rewrites
    RewriteLog logs/rewrite.log
    RewriteLogLevel 2
    

    Put this in any globally scoped area of httpd.conf; I put it around the entries that were already there about logging but you can also just put it at the end if you like that better. In addition, the basics around rewrite troubleshooting includes (apologies if this basic):

    1. make sure that your httpd.conf has AllowOverride All and Options FollowSymLinks set for the directories you serving Restler out of.
    2. You can put all of the configuration into httpd.conf and avoid .htaccess files altogether (and it's a bit faster that way too) but if you do that remember that httpd.conf has absolute url referencing versus .htaccess's relative.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 stm32f103c8t6采集HLK-LD2450毫米波雷达传感器数据并打印显示距离和角度
  • ¥15 不重复生成字母+数字交易号
  • ¥15 AD封装导入后层混乱了
  • ¥15 如何将excel中的数据导入ansys中
  • ¥15 MATLAB中图像问题
  • ¥15 rk3399 安卓7.1 应用音频无声音
  • ¥20 Chatgpt被封号以后,换用apple和gmail注册失败,直接跳转封号界面
  • ¥15 这几个有点疑问解答一下
  • ¥15 r语言如何绘制这样的降水地图
  • ¥15 服务器一块硬盘重启过程中安装后,硬盘不识别了怎么修复?