Intelligencia URLRewriter用于不存在或非aspx页面

时间:2012-09-20 03:49:24

标签: asp.net url-rewriting web-config

我正在尝试将所有不存在的网页重定向到其他域,因为我的博客已移至其他域。

所以 www.mydomain.com/blog/asdf 应该重定向到 blog.mydomain.com/blog/asdf

使用Intelligencia URLRewriter模块我可以重定向博客/但是如果我做博客/某事我会得到404.

即使有一个没有像这样的正则表达式的简单规则,它也不适用于博客文件夹下的任何内容

<rewrite url="~/blog/^" to="http://blog.softwaresynergy.com/blog/" />

我也尝试过强制所有请求转到处理程序

<modules runAllManagedModulesForAllRequests="true">

关于如何在博客/下重定向到其他域名的所有想法?

4 个答案:

答案 0 :(得分:0)

尝试使用以下重定向规则:

<redirect url="^/blog/(.+)$" to="http://blog.softwaresynergy.com/blog/$1" />

把它放在你的其他重写规则的顶部,所以它先被执行,我认为它应该有效。

答案 1 :(得分:0)

网址重写不允许在其他域或子域上重写路径。您可以在global.asax中使用此代码重定向网址:

void Application_BeginRequest(object sender, EventArgs e)
{
    string path = Request.Path;
    if (path.Contains("blog/"))
    {
        HttpContext.Current.Response.Redirect("http://blog.softwaresynergy.com/blog/");
    }
}

答案 2 :(得分:0)

使用自定义404页面。

<system.webServer>
    <httpErrors existingResponse="Replace" errorMode="Custom">
      <remove statusCode="404"/>
      <error statusCode="404" path="/Custom404.aspx" responseMode="Redirect"  />

<customErrors mode="On">
            <error statusCode="404" redirect="/custom404.aspx" />

在custom404页面中,我将代码放入我的重定向。获取导致错误的路径可能是......

的组合
Request.QueryString("aspxerrorpath");
Request.UrlReferrer;

一旦我有了他们试图访问的路径,就进行重定向。

Response.Redirect(NEW_SITE + PATH, true);

答案 3 :(得分:0)

我以不同的方式做了改变。将原始网站保留为php并使用php重写进行重定向,效果很好。

在域new.mydomain中我做了aspx站点

不理想,但现在工作。

相关问题