homepage Welcome to WebmasterWorld Guest from 174.129.76.87
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
301 Redirect for WIX Ajax cached URLs
How to create 301 redirects for the WIX Ajax URLs that have been cached.
mdsww

5+ Year Member



 
Msg#: 4526219 posted 2:11 am on Dec 9, 2012 (gmt 0)

Hi,

I have a site that has been cached in Google. The site originally was a WIX site, so all of the URLs were preceded with a hash and exclamation point (#!) and were cached by Google.

Now I have migrated the site to a wordpress installation on another server. Normally I use .htaccess to rewrite with 301 status for the redirection, however this method does not work for the WIX Ajax cached results.

e.g.

www.example.com/page1
www.example.com/#!ajaxpage1


Here is a normal procedure in .htaccess to achieve this:

RewriteRule ^page1$ "http\:\/\/www\.example\.com\/page1" [R=301,L]
RewriteRule ^#!ajaxpage1$ "http\:\/\/www\.example\.com\/\#\!ajaxpage1" [R=301,L]


The first line works, but the second line doesn't. I think the server ignores everything starting from the hash, because the page served is the homepage.

Please help us do a 301 redirect correctly for the the WIX Ajax pages that are cached by Google.

Thanks in advance.

 

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4526219 posted 7:20 am on Dec 9, 2012 (gmt 0)

<digression>
Here is a normal procedure
<snip>
"http\:\/\/www\.example\.com\/page1"

Normal? Yes, probably, since "normal" is a statistical word. Correct or desirable? No. Quotation marks aren't needed in a mod_rewrite target. Nothing in a mod_rewrite target should be escaped. Slashes / and colons : * never need to be escaped in mod_rewrite.
</digression>

Do a Forums search for "hashbang". You may not be happy with the results, but at least nobody has to dig up the explanation all over again.

This [webmasterworld.com] is the longest recent discussion I could find. Or at least the longest halfway useful one. (There's a nearby thread [webmasterworld.com] where I think all the respondents ended up stumbling away in tears, one by one. The words "splash screen" were used at some point.) Somewhere along the line, someone pointed to this google page [developers.google.com].

:: returning after prolonged masochistic visit to pages that are pretty much Hungarian to me ::

It hardly needs saying that google's definition of "pretty URL" and "ugly URL" has no relationship to the way the words are used in the rest of the known universe. But never mind that. Those are literal _ lowlines in the quotation.

Each URL that contains a hash fragment beginning with the exclamation mark is considered a #! URL. Note that any URL may contain at most one hash fragment. Each pretty (#!) URL has a corresponding ugly (_escaped_fragment_) URL, which is derived with the following steps:

1. The hash fragment becomes part of the query parameters.
2. The hash fragment is indicated in the query parameters by preceding it with _escaped_fragment_=
3. Some characters are escaped when the hash fragment becomes part of the query parameters. These characters are listed below.
4. All other parts of the URL (host, port, path, existing query parameters, and so on) remain unchanged.



* Yes, OK, maybe if you're setting a cookie in mod_rewrite and the developer stuck you with cookies containing literal colons.

mdsww

5+ Year Member



 
Msg#: 4526219 posted 8:30 am on Dec 10, 2012 (gmt 0)

Firstly Lucy, thank you for making my day, great response. My brain is still hurting....

With regard to your response about rewrites, are you saying that the following will work?:

RewriteRule ^page1$ http://www.example.com/page1 [R=301,L]


For the hashbang URL, I assume you saying that you don't think it is possible with .htaccess (or did I miss the point!?)

I Googled "how to create a 301 for hash bang URLs" and found a result that explained that Google does index these URLs, so maybe the "canonical" tag on the homepage is the only way to go.

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4526219 posted 9:03 am on Dec 10, 2012 (gmt 0)

Remove all escaping, and the quotes, from the rule target URL.

The ! means NOT in a RegEx pattern. The literal ! from a URL will normally need to be escaped in RegEx patterns.

From that, you might expect this to work
RewriteRule ^#\!ajaxpage1$ http://www.example.com/somepage [R=301,L]
but it will not, due to the # in the URL and due to the fact that #! is an AJAX URL.

Firstly, for URL with page fragment (i.e. just # not #!) everything after the # in the URL is never requested from the server. For the URL
www.example.com/page#fragment the browser requests /page from www.example.com and when the page is delivered the browser visually auto-scrolls down to the named anchor or id "fragment" part of the page.

However the URL with #! is an AJAX URL and again everything after the #! is not requested from the server in that form. The URL you see in the address bar is NOT the URL that is requested from the server. Instead the part after #! is converted to use normal query string parameters by the javascript running in the browser and eventually this alternative URL is requested from the server:
www.example.com/somestuff?_escaped_fragment_=ajaxpage.

For the URL
www.example.com/#!ajaxpage the browser requests /?_escaped_fragment_=ajaxpage from www.example.com

You can then "look" at this URL request with:
RewriteCond %{QUERY_STRING} (^|&)_escaped_fragment_=ajaxpage(&|$)
RewriteRule ^$ http://www.example.com/somepage [R=301,L]

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4526219 posted 5:41 pm on Dec 10, 2012 (gmt 0)

are you saying that the following will work?

Yup. Plain, literal text.

If you consolidate what google said and what g1 said, you will see that your hashbang URLs can be redirected-- but you don't use the form in google's index. Details will depend on whether there is a pre-existing query string, separate from the hashbang. If so, you need to capture it. Notice that google doesn't say whether the _escaped_fragment_ part goes at the beginning, end or somewhere in the middle of the rest of the query, if any.

So come back with a couple of representative URLs-- in their google-indexed form-- and we'll see what can be done. Unlike most questions hitting this forum, this one has not been asked an average of once a week for the past ten years. So it will be educational for everyone ;)

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4526219 posted 6:56 pm on Dec 10, 2012 (gmt 0)

Yes, this is where the Live HTTP Heasers extension for Firefox is very useful.

It shows you the literal GET or POST URL request that the browser makes.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved