且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

剪切“?_escaped_fragment_ ="并重定向到html/php

更新时间:2023-09-28 23:11:04

请注意,_escaped_fragment_ URL参数是

Note that the _escaped_fragment_ URL parameter was part of Google's AJAX crawling specification (deprecated since Oct 2015) using #! style URLs - so make sure your site is not making use of this still.

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

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

This is the right idea, in that you need to examine the value of the QUERY_STRING server variable, however, the target URL is possibly incorrect. (It might have been correct if you were still using this specification.)

请尝试以下类似方法:

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.

The above should redirect a URL of the form example.com/somedir/3.html?_escaped_fragment_=<anything> to example.com/somedir/3.html.

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

The QSD flag (Apache 2.4+) is necessary to remove the query string from the target URL.

请注意,这是302(临时)重定向.一旦确认它可以正常工作,请仅更改为301(永久)重定向,以避免缓存问题.浏览器会永久缓存301重定向(包括任何错误的重定向).

Note that this is a 302 (temporary) redirect. Only change to a 301 (permanent) redirect once you have confirmed it is working OK - in order to avoid caching issues. 301 redirects are cached persistently by the browser (including any erroneous redirects).

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

用户通常不会输入这样的链接.它们甚至不应链接到搜索引擎或由搜索引擎获取,除非在某个时候可能存在站点配置错误?因此,根据链接这些URL的方式/位置(在GSC中检查报告),您甚至可以考虑阻止这些URL?例如:

Users wouldn't normally enter links like this. They shouldn't even be linked to or picked up by search engines unless there was perhaps a site-misconfiguration at some point? So, depending on how/where these URLs are being linked from (check the report in GSC) then you could even consider blocking these URLs instead? For example:

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

上面的代码将返回403 Forbidden.

The above would return a 403 Forbidden instead.