剪切“?_escaped_fragment_ ="并重定向到html/php [英] Cut "?_escaped_fragment_=" and redirect to html/php

查看:65
本文介绍了剪切“?_escaped_fragment_ ="并重定向到html/php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I see some links in Google Search Console and they look like this:

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

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

How to cut this part: ?_escaped_fragment_= and redirect to the current html/php file?

应该是这样的:

  • 用户输入此链接:example.com/somedir/3.html?_escaped_fragment_=
  • 并重定向到example.com/somedir/3.html
  • User enters this link: example.com/somedir/3.html?_escaped_fragment_=
  • and redirected to example.com/somedir/3.html

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

I found a possible way, but I can't redo it for myself... This "RewriteRule" redirecting to main page. But I don't need this feature...

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

请帮助.

推荐答案

请注意,_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.

这篇关于剪切“?_escaped_fragment_ ="并重定向到html/php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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