0

I have created a simple page in my website to count the outgoing clicks on hyperlinks those members send in forum. I convert the links starting with blah to linkout.asp?u=blah and this is the source of linkout.asp

<%
url=request("u")
response.redirect url
%>

However the validators and Google analytics warn me about 404 or 500 errors that happens on those external websites. It seems that those target pages seems a part of my own website and those errors are counted as internal errors. What is the correct way to use response.redirect to emphasise that those target pages are not my own?

Ali Sheikhpour
  • 10,475
  • 5
  • 41
  • 82
  • 3
    `Response.Redirect` executes a "302 Object moved" header redirect, if Google Analytics is reporting errors it's because there's an issue with your redirect code, and an error is being returned rather than the redirect being executed. The sample code you provided is redirecting to a variable that doesn't exist. You should be redirecting to `url`, not `u`. – Adam Jun 08 '20 at 14:34
  • Thank you. I have updated the question. The variable u was typo when writing the question here not in my real code. @Adam – Ali Sheikhpour Jun 09 '20 at 05:17
  • As far as I'm aware, Google Analytics will only log error codes generated on the domain the analytics JS is running on, which means it's still an issue with your code. Are you using a regular expression to validate URLs before redirecting? Or are you using linkout.asp to perform internal redirects too? – Adam Jun 09 '20 at 07:44

1 Answers1

1

You could try client-side redirection.

For example, something like this should provide you an opportunity to thank visitors, present a disclaimer, and provide users who disable JavaScript a means to access the external site, and hopefully thwart the evil consequences of Google Analytics...

<html>
<head>
<meta http-equiv="refresh" content="3;url=<%= request("u") %>" />
<title>Redirecting...</title>
<script type="text/javascript">
var tmr = null;
function doRedirect() {
    window.location.href = '<%= request("u") %>';
}
window.onload = function() {
    tmr = window.setTimeout(doRedirect, 3000);
}
window.onunload = function() {
    window.clearTimeout(tmr);
    tmr = null;
}
</script>
</head>
<body>
<p>Thank you for visiting our site.  You will be redirected to <%= request("u") %> in 3 seconds</p>
<p>We take no responsiblity for the content displayed on external sites.</p>
<noscript>
<p>If you are not redirected, please <a href="<%= request("u") %>">click here</a> to navigate to the site.</p>
</script>
</body>
</html>

Please note: The above code should not be used in a production environment, since request("u") is not validated nor sanitized before use. Please take additional precautions about confirming all input parameters before relying on them.

Hope this helps.

leeharvey1
  • 1,316
  • 9
  • 14