首页 文章

使用 BlogEngine 进行 URL 重定向

提问于
浏览
3

我正在将博客从 dasBlog 移动到 BlogEngine。在 dasBlog 中,我的网址看起来像这样。

http://pfsolutions-mi.com/blog/2008/03/08/Beyond-Compare.aspx

而在 BlogEngine 中,我的网址看起来像这样。

http://pfsolutions-mi.com/blog/post/2008/03/08/Beyond-Compare.aspx

两个 URL 之间的唯一区别是 BlogEngine 中的“post”sub-folder。

由于我目前正在使用 IIS URL Rewrite 从 URL 中删除 WWW,我认为最简单的解决方案是创建另一个规则来处理添加 sub-folder。我试过这样的事。

rule name =“Blog Redirect”enabled =“true”stopProcessing =“true”

match url =“^ blog /([5] )/([6] )/([7] )/([8])。([9])$”

action type =“Redirect”url =“blog/post/ {。10}/{。11}/{}/{。13}。{。14}”redirectType =“Temporary”

但是,当我输入旧的 dasBlog URL 时,它不会被重定向到新位置。相反,我得到了通用的 BlogEngine 404 错误页面。

注意:一旦我知道一切正常,我计划将 redirectType 更改为 Permanent。

1 回答

  • 1

    您的匹配正则表达式不应该更像这样吗?

    match url="^blog/([0-9]+)/([0-9]+)/([0-9]+)/([\w-]+)\.([a-z]+)$"
    

    无论如何,日期编号中没有下划线,并且[_0-9a-z-]+不包括“Beyond-Compare”中的大写字母。

    所以这里我们应该有:url =“^ blog/digits/digits/digits/any-word-characters.lowercase-letters $”

    我们还可以指定更多:

    match url="^blog/([0-9]{2,4})/([0-9]{2})/([0-9]{2})/([\w-]+)\.([a-z]{3,4})$"
    

    基于您总是拥有的假设:

    • 年份为“08”或“2008”

    • 月份和日期为“01”或“11”

    • 文件结尾有 3 或 4 个小写字母(htm,html,php,asp,aspx,etc.)

    编辑:我认为“\ w”不包括连字符,所以你必须把它变成“[6]”

相关问题