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?
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.
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/");
}
}
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);
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.