• 请不要在回答技术问题时复制粘贴 AI 生成的内容
Reign
V2EX  ›  程序员

form 表单通过 GET 方式提交的 URL,怎样自定义它的形式?

  •  
  •   Reign · Feb 16, 2017 · 3688 views
    This topic created in 3570 days ago, the information mentioned may be changed or developed.

    目前网站的站内搜索功能,想按照 microdata 方式来写, schema.org 给出的参考例子为: https://schema.org/SearchAction , 如下代码:

    <link itemprop="url" href="http://www.example.com/"/>
    
    <form itemprop="potentialAction" itemscope itemtype="http://schema.org/SearchAction">
    
          <meta itemprop="target" content="http://example.com/search?q={query}"/>
          
      <input itemprop="query-input" type="text" name="query"/>
      
      <input type="submit"/>
      
    </form>
    
    这样 form 表单最终生成的 URL 就不是伪静态的了,与 SEO 的原则违背,我想最终提交的表单生成的 URL 为这种样式: www 。 example 。 com/search/this-is-my-query-words.html ,目前只想到两种方法:
    1. 用 js 阻止 form 的 submit(),然后用 js 构造 URL 再跳转
    2. form 表单提交后的 URL ,服务器 header 301 的跳转到 www 。 example 。 com/search/this-is-my-query-words.html

    上面两种方法貌似都不太好,求 V2 们给出最合理的答案,谢谢

    7 replies  •  2017-02-17 02:47:38 +08:00
    Felldeadbird
    Felldeadbird
    Feb 16, 2017
    1
    你用 form GET 提交就会变成不友好的。所以用第一个方法吧。
    1762628386
    1762628386
    Feb 16, 2017
    2
    表单 GET 方式提交的 URL 搜索引擎根本不感兴趣 也不会去抓取 也没法去抓取
    Reign
    Reign
    OP
    Feb 16, 2017
    3
    @1762628386 我会将用户搜索的 URL 存到 sitemap 里面去
    nfroot
    nfroot
    Feb 16, 2017
    4
    扯了这么长还是没说清楚自己想要什么样的。

    “求 V2 们给出最合理的答案”

    你是要我们玩猜谜游戏吗,那起码给点提示好么
    eirk2004
    eirk2004
    Feb 16, 2017
    5
    http://example.com/search?q={query}
    ->
    http://example.com/search/this-is-my-query-words.html

    写一条 rewrite 规则,我没理解错吧
    keller
    keller
    Feb 16, 2017
    6
    seo ? 弄个热门搜索呗
    halden
    halden
    Feb 17, 2017
    7
    搜索引擎好像不会去抓你动态生成的 query words 吧?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3685 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 04:02 · PVG 12:02 · LAX 20:02 · JFK 23:02
    ♥ Do have faith in what you're doing.