Intelligencia URLRewriter for non existent or non aspx pages

╄→гoц情女王★ 提交于 2019-12-11 03:05:44

问题


I am trying to redirect all non existent pages to a different domain, as my blog was moved to a different domain.

So www.mydomain.com/blog/asdf should redirect to blog.mydomain.com/blog/asdf

Using Intelligencia URLRewriter module I can redirect blog/ but if I do blog/something I get a 404.

Even with a simple rule without regex like this one, it doesn't work for anything under the blog folder

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

I also tried this to force all requests to go to the handler

<modules runAllManagedModulesForAllRequests="true">

Any ideas on how to pick up everything under blog/ and redirect to the other domain?


回答1:


Try with following redirect rule:

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

put it at the top of your other rewrite rules, so it gets executed first, I think it should work.




回答2:


URL Rewriting does not allow to rewrite path on other domain or subdomain. You can redirect the url by using this code in 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/");
    }
}



回答3:


Use a custom 404 page.

<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" />

Inside the custom404 page I'd put code to do my redirect. Getting the path that caused the error would probably be a combination of...

Request.QueryString("aspxerrorpath");
Request.UrlReferrer;

Once I have the path they were trying to access just do a redirect.

Response.Redirect(NEW_SITE + PATH, true);



回答4:


I did the change in a different way. Left the original site as php and did the redirect using php rewrite which works fine.

In the domain new.mydomain I did the aspx site

Not ideal, but worked for now.



来源:https://stackoverflow.com/questions/12505834/intelligencia-urlrewriter-for-non-existent-or-non-aspx-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!