@Giberno : 看来你不明白 pennylane 在问什么。
pennylane 尝试通过 IIS/web.config 重定向的全部原因是搜索引擎机器人被重定向到静态预生成的 .htm/.html 文件。
下一代机器人,如 googlebot,可以识别 hashbang。
hashbang = '#!' in 'http://example.com/#!/some/page/with/ajax/content'
当机器人在 url 中检测到这个 hashbang 时,它会将 url 转换为 _escaped_fragment_ 查询字符串 url。
上面的例子将被转换为:
'http://example.com/?_escaped_fragment_=/some/page/with/ajax/content'
这是因为机器人无法执行 javascrip。然而你给出了一个javascript解决方案?如果我错了,请启发我。
更多信息AJAX Applications and SEO
@pennylane:我也在尝试做同样的事情,我想我明白了。
情况:
当我浏览到快照时,快照会显示状态码 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>
重定向规则说明:
匹配:
<match url="(.*)"/>
在任何 url 上调用该规则。
条件:
<add input="{QUERY_STRING}" pattern="_escaped_fragment_=/([_0-9a-zA-Z-]+)" />
如果 '_escaped_fragment_=/' 后跟一个字母数字字符串,有或没有大小写字符、下划线 (_) 或连字符 (-) ...
重写动作:
<action type="Rewrite" url="snapshots/snapshot_{C:1}.html" appendQueryString="false" />
在不附加查询字符串的情况下重写 url。
其中 {C:1} = '_escaped_fragment_' 查询字符串参数的值
信息来源:
我根据以下信息构建了这个重写规则:
结果:
浏览到:
'http://example.com/?_escaped_fragment_=/test'
应该改写为:
GET 'http://example.com/snapshots/snapshot_test.html'
测试模式 {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>
For more info on IIS rewrite testing
另外:
为规范 url 和 sitemap.xml 使用漂亮的 url。
Pretty url: 'http://example.com/#!/test'
Ugly url: 'http://example.com/?_escaped_fragment_=/test'