Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using _escaped_fragment_ to redirect Google to non-ajax pages. I have the following rewrite rule:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$
RewriteRule ^$ /seo.php [QSA,L]

Which works fine except for /, because my rules needs #! to redirect to /seo.php

How do I redirect / to /#! so that Google bot will replace it with _escaped_fragment_ and then be redirected to my /seo.php page ?

share|improve this question
"How do I redirect / to /#! ?" - A bit confused... your question doesn't appear to relate to the rest of your question text? – w3dk Feb 9 '14 at 20:31
I updated the question. – Giann Feb 10 '14 at 5:48
up vote 3 down vote accepted

How do I redirect / to /#!

I don't think you can! At least not in the way you want to, that will be picked up by the Googlebot.

The problem here is that / and /#! are exactly the same URL as far as the server is concerned. The fragment identifier (#!) is never passed to the server. So, when you redirect, you end up with a redirect loop. For example, the following results in a redirect loop:

RewriteRule ^$ /#! [NE,R=301,L]

(The NE flag is required here to prevent the # (special character) being %-encoded.)

You need to be able to set some other condition, that you can check for after the initial redirect, in order to prevent further redirects (a redirect loop). This could be done by either setting a query string (which messes up your pretty URL) or setting a cookie (not supported by Googlebot). So, therefore I don't think you can do this, unless there is some trick I've missed?

HOWEVER, I don't think you need to do this in order to get Google to request the alternative _escape_fragment_ URL for your bare domain. Google provides a mechanism for this in the way of a meta tag:

<meta name="fragment" content="!">

Place this meta tag in the head section of your root document (only). Google should then request www.example.com?_escaped_fragment_=, so your internal rewrite should now work. This is covered in Google's specification.

Just a minor point, in your RewriteCond directive (above) you don't appear to be doing anything with the captured subpattern, so the parentheses can be removed:

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=.*$

In fact, you could probably just check for:

RewriteCond %{QUERY_STRING} ^_escaped_fragment_=
share|improve this answer
I already have the meta fragment. When I fetch the URL with Google Webmaster tools, it doesn't seems to use escaped_fragment and is not redirected. – Giann Feb 10 '14 at 22:12
Yes, I see the same in my logs too. However, this is not entirely unexpected. Since the meta tag is contained in the page, Google is only going to know that it should use the _escape_fragment_ in future after the initial page request. I would expect Googlebot to make a second request when actually indexing your site with the _escape_fragment_ in this instance. However, I can't confirm this at the current time. Is your site very new? Do you see anything in your access logs? – w3dk Feb 11 '14 at 2:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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