1

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

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

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

It should be like this:

  • User enters this link: example.com/somedir/3.html?_escaped_fragment_=
  • and redirected to example.com/somedir/3.html

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]

Please help.

1 Answer 1

1

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]

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.)

Try something like the following instead:

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

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

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

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).


User enters this link: example.com/somedir/3.html?_escaped_fragment_=

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]

The above would return a 403 Forbidden instead.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.