0

I have set up error pages in IIS as an httpRedirect.htm, trying to convert any http request to https, when error 403.4 is caught.

So if a user types a http url to the browser, it triggers httpRedirect.htm page and will get this url, replace http to https and then redirect to this new url. I want this happen in javascript.

However, when I use document.referrer in httpRedirect.htm, I found it always returns blank.

Is there any special consideration for this situation? Can the browser using this error page carry the information from the previous request?

1
  • You can never rely on document.referrer. And deocument.referrer is ALWAYS blank when coming from a bookmark or typed in address. Use information in the URL
    – mplungjan
    Jul 17, 2013 at 17:16

1 Answer 1

0

You will have to look at the location object. The redirect is on the server-side.

Scenarios:

  1. You go directly to http://example.com/index.html, and httpRedirect.htm is rendered. Since that´s the first page you are visiting, the referrer is empty.
  2. You are at http://test.com/index.html and clicks on a link to http://example.com/index.html. You are now seeing httpRedirect.html, but the referrer is the page before, which is http://test.com/index.html.

Since the referrer depends on your browser, you can´t be sure to have anything in the referrer object at all, even if it "should" be something there. Some firewalls and anti-virus applications might disguise is at well.

If you are at http://example.com/index.html and is seeing httpRedirect.htm, the location.href is still http://example.com/index.html though.

You can see some example code using location here: http://kloudgate.wordpress.com/2013/05/30/how-to-redirect-http-to-https-using-iis7-0/

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.