Mobile app version of vmapp.org
Login or Join
Carla537

: How to redirect / to /#! 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

@Carla537

Posted in: #Seo #WebApplications

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 ?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Carla537

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

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 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_=

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme