我使用IIS重写模块来处理博客之间的迁移,以便在迁移过程中不会中断链接。所以我真的只是使用了很多301重定向。
然而,我想避免重定向时,可能的性能和搜索引擎优化的原因。我可以通过在代码中复制我的规则来做到这一点。但我想我应该先问一下。是否有一种方法可以重用重写模块的规则来预处理和重新格式化链接?
以下是博客主题的摘录……
<a rel="bookmark" href="<%=Post.PermaLink %>" title="<%=Server.HtmlEncode(Post.Title) %>">Permalink</a>我希望将其更改为类似于href="ReformatLink(Post.PermaLink)"的内容,其中ReformatLink在指定的URL上运行url重写规则,并返回新的URL。
发布于 2012-08-14 02:40:58
我找到了另一种方法。我可以通过修改BlogEngine.Core来创建我想要的链接格式。在Post.cs中,我只需更改属性PermaLink和RelativeLink,以反映旧博客软件的链接结构。
我将暂时保留我的重写模块规则,以防我遗漏了什么。但这似乎解决了这个问题。
发布于 2012-08-14 02:49:34
我正在使用这个库http://www.iis.net/download/urlrewrite,并且我正在做类似于下面的事情。
<rule name="FolderAndNoQueryString" stopProcessing="true">
<match url="^([^/]+)/([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<!-- The following condition prevents rule from rewriting requests to .axd files -->
<add input="{URL}" negate="true" pattern="\.axd$" />
</conditions>
<action type="Rewrite" url="{R:1}/{R:2}.aspx" />
</rule>在我的HTML代码中,我有以下内容;
<a href="<%=AppSettings("ApplicationPath") %>Folder/MyActualASPXPage">My Link</a>ApplicationPath只是一个普通的Web.Config密钥,如下所示;
<add key="ApplicationPath" value="/MyVirtualDir/" />https://stackoverflow.com/questions/11939918
复制相似问题