2012-08-13 69 views
0

我正在使用IIS重写模块来照顾博客之间的迁移,以便在此过程中没有任何链接被中断。所以我真的只是使用了很多301重定向。IIS 7.5 URL重写模块重新格式化链接?

但是,我想避免重定向时可能的性能和搜索引擎优化的原因。我可以通过在代码中复制我的规则来做到这一点。但我想我会先问。有没有办法重用重写模块的规则来预处理和重新格式化链接?

以下是从博客主题的摘录...

<a rel="bookmark" href="<%=Post.PermaLink %>" title="<%=Server.HtmlEncode(Post.Title) %>">Permalink</a> 

我想改变这有点像href="ReformatLink(Post.PermaLink)",其中ReformatLink运行于指定URL的URL重写规则,并返回新URL。

回答

1

我找到了另一种方法。我可以通过修改BlogEngine.Core来创建我想要的链接格式。在Post.cs中,我只需更改属性PermaLinkRelativeLink以反映旧博客软件的链接结构。

现在,我将保留我的重写模块规则,以防万一我遗漏了某些东西。但这似乎照顾到了这个问题。

0

我在使用这个库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 Key,如下所示;

<add key="ApplicationPath" value="/MyVirtualDir/" />