我已经使用hash bang开始了ajax站点路径
目前我的网址看起来像:
http://www.domain.com/#!/index
http://www.domain.com/#!/studio
http://www.domain.com/#!/about
Run Code Online (Sandbox Code Playgroud)
从阅读谷歌的文档: http://code.google.com/web/ajaxcrawling/
它看起来像谷歌将尝试重写http://www.domain.com/#!/工作室
http://www.domain.com/?_escaped_fragment_=studio
我想知道如何获得IIS7重写规则将转义的片段重定向到:
http://www.domain.com/studio 即获取查询字符串arg并将其映射回根目录
该网站是使用umbraco在asp.net中完成的,所以我也可以访问umbraco的重写配置文件!
干杯
@Giberno:看来你不明白pennylane在问什么.
pennylane尝试通过IIS/web.config重定向的全部原因是搜索引擎机器人被重定向到静态预生成的.htm/.html文件.
下一代机器人,如googlebot,认识到一个混乱.
hashbang = '#!' in 'http://example.com/#!/some/page/with/ajax/content'
Run Code Online (Sandbox Code Playgroud)
当机器人在url中检测到这个hashbang时,它会将url转换为_escaped_fragment_查询字符串url.
上面的例子将转换为:
'http://example.com/?_escaped_fragment_=/some/page/with/ajax/content'
Run Code Online (Sandbox Code Playgroud)
这是因为机器人无法执行javascrip.然而你提供了一个JavaScript解决方案?如果我错了,请启发我.
有关AJAX应用程序和SEO的更多信息
@pennylane:我正在努力做同样的事情,我想我得到了它.
情况:
snapshot name ='snapshot_ {page}'其中{page} =页面名称
当我浏览快照时,快照显示状态码为200 OK.
我为web.config文件放置了以下重写规则:
<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>
Run Code Online (Sandbox Code Playgroud)
重定向规则扩充:
比赛:
<match url="(.*)"/>
Run Code Online (Sandbox Code Playgroud)
任何网址都会调用该规则.
条件:
<add input="{QUERY_STRING}" pattern="_escaped_fragment_=/([_0-9a-zA-Z-]+)" />
Run Code Online (Sandbox Code Playgroud)
如果'_escaped_fragment _ = /'后跟一个alphanumiriq字符串,带或不带套接字符,下划线(_)或连字符( - )......
重写行动:
<action type="Rewrite" url="snapshots/snapshot_{C:1}.html" appendQueryString="false" />
Run Code Online (Sandbox Code Playgroud)
重写到url而不附加查询字符串.
其中{C:1} ='_escaped_fragment_'查询字符串参数的值
信息来源: 我根据以下信息构建了这个重写规则:
结果:
浏览到:
'http://example.com/?_escaped_fragment_=/test'
Run Code Online (Sandbox Code Playgroud)
应改写为:
GET 'http://example.com/snapshots/snapshot_test.html'
Run Code Online (Sandbox Code Playgroud)
测试模式{C:1} ='test'.
测试:
在我看来,测试重写规则是否有效的最简单方法是遵循以下步骤:
<%@ 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>
Run Code Online (Sandbox Code Playgroud)
最后在浏览器中输入以下网址:
此外:
使用规范网址和sitemap.xml的漂亮网址.
Pretty url: 'http://example.com/#!/test'
Ugly url: 'http://example.com/?_escaped_fragment_=/test'
Run Code Online (Sandbox Code Playgroud)
试着做:
JavaScript 代码:
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();
});
Run Code Online (Sandbox Code Playgroud)
HTML 代码:
<div id="content"><!--#include file="process_page.asp"--></div>
Run Code Online (Sandbox Code Playgroud)
在 process_page.asp 中:
做某事GET _escaped_fragment_
您还可以参考: http: //www.gingerhost.com/ajax-demo/
顺便说一句:我不擅长asp。我的主要语言是php。但我做了上面的代码并且不需要 url 重写