К основному контенту

Custom errors in classic ASP on IIS7 and Vista

Spent a few hours the other day trying to solve an issue I had with Vista and IIS7 using Classic ASP. Basically I couldn't get the 404 error to redirect to a custom page. I tried various methods but all failed. IIS6 was simple IIS7 just didn't work.

The reason for doing this was to allow "friendly URLS" on IIS6. This is basically where you can have www.mysite.com/aboutus and it'll redirect to a dynamic URL. It's done using a meta tag that creates a friendly redirect AND using a custom 404 page.

In IIS6 this is easy to setup, just specify your 404.asp page, and any requests that aren't found are redirected to:-

404.asp?404;http://{HTTP_HOST}:{SERVER_PORT}{HTTP_URL}

with the {} values replaced obviously.

Your page then picks out the relevant URL and redirects accordingly.

Now in IIS7 I couldn't get this to work so eventually I found a work around.

1. Go to this page and download the URL Rewrite module
2. Install it and then against the site you want to edit go into the module and create a rule with the following settings:-

a. Requested URL "does not match the pattern"
b. "*.*" as the pattern (this assumes you are doing /aboutus and not /aboutus.htm)
c. Action = "redirect"
d. redirect URL = 404.asp?404;http://{HTTP_HOST}:{SERVER_PORT}{HTTP_URL}

(replace 404.asp with your asp page handling the redirect)

Leave everything else as default.

Once done you end up with a redirect that works just like the 404.asp custom page and you can now use the same code you might use on the live 2000/2003 server running IIS6 and it should work perfectly!

Hope it helps

Комментарии

Популярные сообщения из этого блога