【问题标题】:Cut "?_escaped_fragment_=" and redirect to html/php剪切“?_escaped_fragment_=”并重定向到 html/php
【发布时间】:2019-05-20 11:01:29
【问题描述】:

我在 Google Search Console 中看到了一些链接,它们看起来像这样:

example.com/somedir/3.html?_escaped_fragment_=

如何剪切这部分:?_escaped_fragment_=并重定向到当前的html/php文件?

应该是这样的:

  • 用户进入此链接:example.com/somedir/3.html?_escaped_fragment_=
  • 并重定向到example.com/somedir/3.html

我找到了一种可能的方法,但我不能自己重做...这个“RewriteRule”重定向到主页。但是我不需要这个功能...

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%1? [L,R=301]

请帮忙。

【问题讨论】:

    标签: .htaccess redirect mod-rewrite


    【解决方案1】:

    请注意,_escaped_fragment_ URL 参数是使用 #! 样式 URL 的 Google's AJAX crawling specification (deprecated since Oct 2015) 的一部分 - 所以请确保您的网站仍然没有使用它。

    RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%1? [L,R=301]
    

    这是正确的想法,因为您需要检查QUERY_STRING 服务器变量的值,但是,目标 URL 可能不正确。 (如果您仍在使用此规范,它可能是正确的。)

    请尝试以下方法:

    RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
    RewriteRule (.*) /$1 [QSD,R=302,L]
    

    以上内容应将example.com/somedir/3.html?_escaped_fragment_=<anything> 形式的URL 重定向到example.com/somedir/3.html

    QSD 标志 (Apache 2.4+) 是从目标 URL 中删除查询字符串所必需的。

    请注意,这是一个 302(临时)重定向。只有在确认它工作正常后才更改为 301(永久)重定向 - 以避免缓存问题。 301 重定向被浏览器永久缓存(包括任何错误的重定向)。


    用户输入此链接:example.com/somedir/3.html?_escaped_fragment_=

    用户通常不会输入这样的链接。除非在某些时候可能存在站点配置错误,否则它们甚至不应该链接到搜索引擎或被搜索引擎拾取?那么,根据这些 URL 的链接方式/位置(查看 GSC 中的报告),您甚至可以考虑改为阻止这些 URL?例如:

    RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
    RewriteRule ^ - [F]
    

    上面会返回一个 403 Forbidden。

    【讨论】:

      猜你喜欢
      • 2014-10-16
      • 2017-09-13
      • 2015-02-17
      • 1970-01-01
      • 2016-07-17
      • 1970-01-01
      • 1970-01-01
      • 2015-10-22
      • 1970-01-01
      相关资源
      最近更新 更多