我怎样才能查询字符串在我的Amazon S3的静态网站? [英] How can I get query strings in my Amazon S3 static website?

查看:132
本文介绍了我怎样才能查询字符串在我的Amazon S3的静态网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我托管在Amazon S3的静态网站。我的一些客户端的JavaScript解析查询字符串来控制HTML。这工作得很好本地,但在S3托管版本中,查询字符串似乎得到从请求下降。

I am hosting a static website on Amazon S3. Some of my client-side javascript parses the query strings to control the HTML. This works fine locally, but on the S3-hosted version, the query strings seem to get dropped from the request.

我为什么要使用查询字符串的是,我希望能够通过基于用户做了previous页面上哪些页面之间的状态。

My motivation for using query strings is that I want to be able to pass state between pages based on what the user did on the previous page.

时的这种做法可能吗?我是不是违反了静态的要求S3静态网站?

Is this approach possible? Did I violate the "static" requirement for S3 static websites?

我似乎无法找到任何提及的S3文档一般查询字符串,除了的验证的东西,我不认为解决我的问题。

I can't seem to find any mention of general query strings in the S3 docs, aside from the authentication stuff, which I don't think solves my problem.

推荐答案

如果你正在使用的索引文件,在这个...

If you are using index documents, where this...

http://bucket.example.com/foo

...实际显示的文档时富/ index.html的那么你的解决方法将是避免S3做之前显示的索引页重定向。

...actually displays the document at foo/index.html then your workaround will be to avoid the redirect that S3 does prior to displaying the index page.

有关的链接指向的页面 /富,其实你应该创建指向 /富/ 而不是(与结尾的斜线后的查询字符串,可能看起来很奇怪,但它是相当有效)。这是因为当你的浏览器请求一个页面时,会导致索引文件中,而是在一个斜线并没有结束,S3发送重定向,使您的浏览器有斜线的URL末尾。如果不是因为这个,该网页上的相关链接会引用错误的道路。

For a link pointing to the page at /foo, you should actually create the link pointing to /foo/ instead (with the query string after the trailing slash; may look strange but it's quite valid). This is because when your browser requests a page that would result in an index document, but doesn't end in a trailing slash, S3 sends a redirect so that your browser has a trailing slash at the end of the URL. If not for this, relative links on that page would be referencing the wrong path.

背后的问题,问题是,当S3发送,从 /富重定向到 /富/ ,它剥离查询字符串。他们没有设计这样的说法,但是这是他们做了什么,有没有出现是因为修改此行为的设置。

The problem underlying the problem is that when S3 sends that redirect from /foo to /foo/, it strips the query string. They didn't have to design it that way, but that's what they did, and there does not appear to be a setting that modifies this behavior.

但是,如果你的链接直接指向 /富/ SOME_THING这里=&放大器; something_else =太而不是指向 /富SOME_THING =这里和放大器? ;。something_else =太(?之前没有尾随斜线 ),然后重定向避免和您的查询字符串应该保持不变。

But if your link points directly to /foo/?some_thing=here&something_else=too instead of pointing to/foo?some_thing=here&something_else=too (no trailing slash before the ?) then the redirect is avoided and your query strings should stay intact.

这篇关于我怎样才能查询字符串在我的Amazon S3的静态网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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