I have started down the ajax site path using hash bang
currently my urls look like:
http://www.domain.com/#!/index
http://www.domain.com/#!/studio
http://www.domain.com/#!/about
from reading google's docs: http://code.google.com/web/ajaxcrawling/
it looks like google will try and rewrite http://www.domain.com/#!/
studio to
ht开发者_开发百科tp://www.domain.com/?_escaped_fragment_=studio
I was wondering how I would get an IIS7 rewrite rule to redirect the escaped fragment to:
http://www.domain.com/studio i.e. take the querystring arg and map it back to the root
the site is done in asp.net using umbraco so i have access to the rewrite config file from umbraco also!
Cheers
@Giberno : It seems that you do not understand what pennylane is asking.
The whole reason pennylane is trying to redirect through IIS / web.config is so that the search engine robots are redirected to a static pre generated .htm/.html file.
The next gen robots, like googlebot, recognise a hashbang.
hashbang = '#!' in 'http://example.com/#!/some/page/with/ajax/content'
When a robot detects this hashbang in the url it will convert the url to a _escaped_fragment_ query string url.
The example from above will be converted to:
'http://example.com/?_escaped_fragment_=/some/page/with/ajax/content'
This because robots can not execute the javascrip. Yet you give a javascript solution? Enlighten me if I am wrong.
More info on AJAX Applications and SEO
@pennylane : I am trying to do the same and I think I got it.
Situation:
- snapshots directory = 'http://example.com/snapshots/...'
snapshot name = 'snapshot_{page}' where {page} = the pagename
ex : 'http://example.com/snapshots/snapshot_contact.html'
When I browse to a snapshot, the snapshot is shown with a statuscode 200 OK.
I placed the following rewrite rule for the web.config file:
<configuration>
<system.webServer>
<rewrite>
<rules>
... other rewrite rules ...
<rule name="EscapedFragment" stopProcessing="true">
<match url="(.*)"/>
<conditions>
<add input="{QUERY_STRING}" pattern="_escaped_fragment_=/([_0-9a-zA-Z-]+)" />
</conditions>
<action type="Rewrite" url="snapshots/snapshot_{C:1}.html" appendQueryString="false" />
</rule>
... other rewrite rules ...
</rules>
</rewrite>
... other configs ...
</system.webServer>
</configuration>
Redirect Rule Explenation:
Match:
<match url="(.*)"/>
The rule is called on any url.
Condition:
<add input="{QUERY_STRING}" pattern="_escaped_fragment_=/([_0-9a-zA-Z-]+)" />
If '_escaped_fragment_=/' is followed by a alphanumiriq string, with or without cased characters, underscore (_) or hyphen (-) ...
Rewrite Action:
<action type="Rewrite" url="snapshots/snapshot_{C:1}.html" appendQueryString="false" />
Rewrite to the url without appending the query string.
Where {C:1} = the value of the '_escaped_fragment_' query string parameter
Info Sources: I constructed this rewrite rule based on the following information:
- Creating Rewrite Rules for the URL Rewrite Module
- URL Rewrite Module 2.0 Configuration Reference : TRACKING CAPTURE GROUPS ACROSS CONDITIONS
- Testing patterns : Testing Rewrite Rule Patterns
Result:
Browsing to:
'http://example.com/?_escaped_fragment_=/test'
Should rewrite to:
GET 'http://example.com/snapshots/snapshot_test.html'
Testing the pattern {C:1} = 'test'.
Testing:
In my opinion the easiest way to test if your rewrite rule is working is to follow these steps:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>URL Rewrite Module Test</title>
</head>
<body>
<h1>URL Rewrite Module Test Page</h1>
<table>
<tr>
<th>Server Variable</th>
<th>Value</th>
</tr>
<tr>
<td>Original URL: </td>
<td><%= Request.ServerVariables["HTTP_X_ORIGINAL_URL"] %></td>
</tr>
<tr>
<td>Final URL: </td>
<td><%= Request.ServerVariables["SCRIPT_NAME"] + "?" + Request.ServerVariables["QUERY_STRING"] %></td>
</tr>
</table>
</body>
</html>
- create a snapshot_test.aspx file under the same directory that contains the code from above.
- change the rewrite rule to rewrite to .aspx files instead of .html files
And finaly enter the following url in your browser:
'http://example.com/?_escaped_fragment_=/test'
For more info on IIS rewrite testing
In addition:
Use the pretty url for the canonical url and the sitemap.xml.
Pretty url: 'http://example.com/#!/test'
Ugly url: 'http://example.com/?_escaped_fragment_=/test'
Try to do:
javascript code:
var hashchange;
function MyHash() {
if(window.location.hash) {
MyHash = window.location.hash.replace("#!/", "");
$.get("process_page.asp?_escaped_fragment_=" + MyHash, function(data) {
$("#content").html(data);
});
}
}
$(document).ready(function() {
hashchange();
});
$(window).bind('hashchange', function() {
hashchange();
});
HTML code:
<div id="content"><!--#include file="process_page.asp"--></div>
and in process_page.asp:
do something to GET
_escaped_fragment_
you can also reference: http://www.gingerhost.com/ajax-demo/
BTW: I am not good at asp. my main language is php. but i did above code and do not need url rewrite
精彩评论