locked
Url Rewriting Concept RRS feed

  • Question

  • User659540077 posted

    Hi,

    I'm trying to do this:

    When I search google for my site I get hits for my site such as www.mysite.com/info. The thing is that the url is old and the correct url should be www.mysite.com/information/now.

    In order for a user to be redirected to the new url when clicking the old url, there are several method to do this.  My question is which is the most easiest way to do this without needing mess with IIS or install additional software. 

    Url rewriting using Global.asx is a method found but will this do the trick? Any suggestions is appreciated.

    Friday, May 25, 2012 4:52 AM

All replies

  • User-661350001 posted

    inside this www.mysite.com/info page do Response.RedirectPermanent(" www.mysite.com/information/now")

    Friday, May 25, 2012 5:04 AM
  • User659540077 posted

    Thanks for your response, but how do you do with pages that no longer exists? 

    E.g old www.mysite.com/items in which I want to redirect to any desired page in my new website?

    Friday, May 25, 2012 6:27 AM
  • User1779161005 posted

    Thanks for your response, but how do you do with pages that no longer exists? 

    E.g old www.mysite.com/items in which I want to redirect to any desired page in my new website?

    You would have to know the old URLs and what new URLs they map to. I know you asked for some way to do this without configuring IIS, but configuring the URL rewrite module in IIS is the preferred way of doing this.

    Friday, May 25, 2012 9:16 AM
  • User659540077 posted

    I tried rewriting the url in Global.asax file like this:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
         Match m = Regex.Match(Request.Url.LocalPath, @"^/old-url/?$");

         if (m.Success)
         {
             HttpContext.Current.RewritePath("~/mysite-submenu/new-url/");
         }

    }

    However I get the "HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." I know when copying the new url and paste it in adressbar it works, but not when rewriting.

    Monday, May 28, 2012 3:41 AM
  • User1779161005 posted

    Does a direct request for ~/mysite-submenu/new-url/ work?

    When you rewrite the path it's supposed to be relative to the app the request is being made to.

    Monday, May 28, 2012 10:50 AM