Google AMP search form redirect to non-AMP page

时间:2018-03-25 20:19:06

标签: amp-html google-amp

With Google AMP pages I want to allow users to enter a search query, which the triggers a redirect to a non-AMP page. So from www.example.com/articles/mynewsarticle/amp I want to redirect to www.example.com/search?q=<userquery>

I'm looking at the amp-form component, but I can't find how to trigger a redirect to a non-amp page with a dynamic search query.

Is it possible to do this?

2 个答案:

答案 0 :(得分:1)

是的,如果我理解正确的话,它是可能的。您需要在表单中使用方法get,并将重定向页面的路径放入action参数中。在表单中放置一个名为“q”的输入字段,它将是用户请求的字段。

<form method="get" action="www.example.com/search">
    <input type="text" name="q" placeholder="Search">
</form>

答案 1 :(得分:1)

实际上,您需要amp形式的组件并将重定向标头直接添加到脚本中。

header("access-control-allow-credentials:true");
header("access-control-allow-headers:Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
header("access-control-allow-methods:POST, GET, OPTIONS");
header("access-control-allow-origin:".$_SERVER['HTTP_ORIGIN']);
header("access-control-expose-headers:AMP-Access-Control-Allow-Source-Origin");
header("amp-access-control-allow-source-origin:https://".$_SERVER['HTTP_HOST']);
header("Content-Type: application/json");
header("Location: your_redirect_url");