0

I am using ASP.NET 2.0 on IIS6 therefore I can’t use system.web.routing. I’ve tried a few URL rewriters but none did what I wanted.

I basically need to transform (read/parse then redirect) URL 1 into 2 with minimum IIS configuration because I don't have the full authority to reconfigure web servers (i.e. ISAP on IIS6 or install 3rd party extensions/libraries). And I can’t transform URL into 3 because all the physical links will break.

  1. http://www.url.com/abc123
  2. http://www.url.com/default.aspx?code=abc123
  3. http://www.url.com/abc123/default.aspx?code=abc123

Thank you!

3 Answers 3

1

Create 404 error handler, e.g. 404.aspx. In that page, parse request URL and extract code using Request.Path. Then, redirect to default.aspx?code=abc123.

You should be able to set 404 (page not found) handler to 404.aspx for your website, most hosting providers allow that.

Sign up to request clarification or add additional context in comments.

8 Comments

I was going to manually do the parsing and redirect in Application_Error (global.asax) because I couldn't get rid of the aspxerrorpath querry string as I can't capture the value of /abc123 before aspxerrorpath is thrown because Request.Path is alwasy the URL of the 404 error page.
Make sure you set 404 handler in IIS, not in web.config.
Do you recommend Application_Error (global.asax) than 404? Becuase I don't have too much control over web servers and we have more than 1 web servers so I prefer the "soft" way. For any IIS setting change, it takes weeks to get approved...
If you get Application_Error event for extension-less URLs like http://www.url.com/abc123 by all means, use it. Otherwise you need to configure IIS to use your 404 handler.
I've configured my dev IIS to forward 404 to my 404 page yet Request.Url and Request.Path both showing the path to 404 page and Request.UrlReferrer is null.
|
0

I would suggest that you look at using a custom transform with UrlRewriter.net. This link details how you can do it with the Intelligencia.UrlRewriter assembly (about 3/4 of the way down the page). Hopefully is good enough to do what you need.

1 Comment

I don't think URL rewrite will work because I don't want the URL to be rewritten I only need the URL to be read/parsed then redirect.
0
protected void Page_Load(object sender, EventArgs e)
{
    HtmlLink canonicalTag = new HtmlLink();
    canonicalTag.Href = "http://www.url.com/default.aspx";
    canonicalTag.Attributes["rel"] = "canonical";
    Page.Header.Controls.Add(canonicalTag);
}

http://codersbarn.com/post/2009/02/21/ASPNET-SEO-and-the-Canonical-Tag.aspx

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.