[英]IIS 7.5 URL Rewrite Module to Reformat Links?
我正在使用IIS重写模块来处理博客之间的迁移,以便在此过程中不会断开任何链接。 因此,我实际上只是使用了很多301重定向。
但是,出于性能和SEO的原因,我想尽可能避免重定向。 我可以通过在代码中复制规则来做到这一点。 但是我想我先问一下。 有没有一种方法可以重用重写模块的规则来预处理和重新格式化链接?
以下是博客主题的摘录...
<a rel="bookmark" href="<%=Post.PermaLink %>" title="<%=Server.HtmlEncode(Post.Title) %>">Permalink</a>
我想将其更改为href="ReformatLink(Post.PermaLink)"
,其中ReformatLink
在指定的URL上运行url重写规则并返回新的URL。
我找到了另一种方式。 我可以通过修改BlogEngine.Core来精确创建所需的链接格式。 在Post.cs内部,我只是更改了PermaLink
和RelativeLink
属性以反映旧博客软件的链接结构。
我会暂时保留我的重写模块规则,以防万一我错过了什么。 但这似乎可以解决问题。
我正在使用此库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/" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.