在下面的所有步骤中,我都是通过远程访问托管服务器来工作的。托管服务器正在运行apache。我的托管公司是godaddy。
我有内容为的db.json
{
"posts": [
{
"title": "JSON SERVER",
"author": "foo",
"id": 1
},
...
]
}
我通过json-server --watch db.json --port 1234
启动了json-server
。
在~/public_html/test-json-server/.htaccess
:中
RewriteEngine On
RewriteRule ^$ http://localhost:1234/posts/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://localhost:1234/posts/$1 [P,L]
现在,访问http://mywebsite.com/test-json-server/
会给出空数据。但如果我访问http://mywebsite.com/test-json-server/1
,它会正确地返回
{
"title": "JSON SERVER",
"author": "foo",
"id": 1
}
如何修复CCD_ 7以使访问CCD_;帖子";数据
当json服务器运行时,我查看了日志,得到了以下信息:
GET /posts/index.html.var 404 7.552 ms - 2
GET /posts/index.html.var 404 2.918 ms - 2
GET /posts/1 304 4.065 ms - -
GET /posts/1 200 2.672 ms - 58
GET /posts/1 200 2.714 ms - 58
当我尝试访问http://mywebsite.com/test-json-server/
时,似乎出现了404错误。
我修复了它。我的htaccess是:
DirectoryIndex disabled
RewriteEngine On
RewriteRule ^$ http://localhost:1234/posts/ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://localhost:1234/posts/$1 [P,L]
非常感谢!