469,904 Members | 1,920 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,904 developers. It's quick & easy.

redirect based on link followed


I have a good feeling this is possible, but do not know where I would start.

I have a few pages at http://www.mydomain.com/whatever.html

Someone has started linking to them with http://www.rubbish.com/mydomain

When you click that second link, it redirects to my html file.

Is there a way that I can break that? The second domain owner isn't about to stop (I have asked) and I would rather it redirect straight to google than come through to my site. I have tried a few Javascripts but I am no coder. I would greatly appreciate any help - my website can handle ASP (and by my limited knowledge, ASP >> Javascript).

Thanks in advance

Oct 16 '07 #1
10 1840
346 Expert 100+
Yes you can do that, and this guy is playing with fire if he's refusing to take the links to your content off his website... you could actually be a real jerk to this guy if you wanted to. Personally, I would redirect the link to a page with adult material just to make a point to him, but that's me.

Anyway, You can check what is called the "referrer", the page that "referred" the end user's browser or directed the user's browser to your page. In this case it would be Http://rubbish.com by your example... and you can check that using the ServerVariables collection in ASP. Once you know that, you can block out anything coming from that domain, or you can just direct elsewhere, or deal with it however you like really.

That is to say.. you could code something like this...

Expand|Select|Wrap|Line Numbers
  1. <%
  2. 'include this at the TOP of every single page in your site (as long as they have an .asp extension of course)
  3.    Referrer = Request.ServerVariable("HTTP_REFERRER")
  4.    If Referrer = "http://www.rubbish.com" Then
  5.       Response.write "Please note that you have come to this page in an illegal manner. Please notify the user of the referring website. Here is his email: <a href='mailto:sombozo@rubbish.com'>Some Bozo</a>."
  6.    End if
  7. %>
Of course, you can deal with it any way you like - redirect to google or any other website, document the intrusion in a database along with ip an all, redirect back to the referring website, etc. Sky is the limit.

Note that you WILL have to include this at the top of all pages in your site if you really want to put a nail in the coffin here, and you WILL have to rename your pages to include the .asp extension. So instead of page.html --> page.asp in order to run this.

Hope this helps you out.

Oct 16 '07 #2
Hi Mark,

Thanks so much for replying.

OK, two kickers to this, I am not sure how much it breaks what you are trying to do.

First, his site, http://rubbish.com, is basically a rip of http://tinyurl.com. He is just redirecting subfolders to my files directly (and numerous others), however, he is posting these links on another forum, so I am wondering what the referrer will be. If it is http://rubbish.com, happy days - but if it is http://www.thirdparty.com (where he posted his rubbish.com link) then that may be an issue. I don't want to block www.thirdparty.com users, just those that click one of his links.

Boy I hope that makes sense :)

Second, my files are relatively well published - renaming extensions to .asp is going to stuff quite a few things up. Could I perhaps do it in two passes? Have my .html redirect to a .asp, keeping the referrer and sending his rubbish.com links to http://www.horridlydisgustingporn.com?

I know I am being difficult, but I am fantastically frustrated at the moment. Ideally I would like to create a page called scumbag.html and redirect people to that page - a little note explaining that they have been duped by a scumbag, and to please note the correct URL (it isn't their fault after all)

Thanks again for responding - I will do some research on what you posted and see if I can kick it to do what I want until you respond.

Oct 16 '07 #3
346 Expert 100+
Hi John,

That's not a problem. There's more than a few ways to skin a cat.

If you can't go around changing the file extensions of your files then you can use javascript, which will run just fine within a .html extension. I'd advise using ASP where ever you can though, simply because once this guy catches on to what you're doing he may visit your site, view the source code - and come up with a workaround, then you're back to the drawing board. (ASP is compiled on server and sent to the visitors browser in plain text, the user can't see the ASP code, and therefore doesn't know what you've done. Javascript is run by the visitor's browser itself, and can easily be viewed by anyone visiting the site.)

In particular, the document.referrer method. (not sure how familar you are with javascript, but place this within the <head></head> tags of your HTML document(s))

Expand|Select|Wrap|Line Numbers
  1. window.onload - checkReferrer;
  2. function checkReferrer() {
  3.    if (document.referrer.indexOf("http://www.ripoffoftinyurl.com") > 0) {
  4.       location.href = "goaway.html";
  5.    }
  6. }
In regards to your other question... It doesn't matter where he posts the links. What matters is the url or domain which sent the user to your pages, that's what you're checking for - and that will always be his "whatever.com" domain.

For instance, if he posts it here - thescripts.com is not the referrer. The browser will first load HIS URL BEFORE redirecting to your page, therefore the referrer will be his domain, even though the user will probably never see it.

If he posts the link here, or writes it on a piece of paper and shoves it down his friend's pants - the code will work because the referring url is still "whatever.com". If I find your site on google the referring url is google.com, or you give me the direct link the referring url will be the last page i visited, or if i open a new browser window with my homepage being about:blank - there is no referring url - The redirect will not mess with my ability to see your page because the referring url does not include "whatever.com".

Hope this helps.
Oct 17 '07 #4
3,406 Expert 2GB
There is a server setting that allows the server to check for ASP code in a file with extension .HTML, but it might slow down the server since the server will be checking for code in every page it serves, still, this might be a more straightforward solution if you still want to use the ASP approach but don't want to rename every file in your site.

Then you could probably do something in the global.asa file to perform a simple script on every page. Mark, you've used the global.asa file to add code to every page, right? I don't think I've ever bothered to try, but it might be a quick fix for your problem.

Oct 17 '07 #5
346 Expert 100+
Well I'm flabergasted. I have no idea why I didn't think of the global.asa - I've only used it a few hundred times for similar solutions...lol

Thanks Jared!


Copy the following code and save it as a new file called global.asa - save this file in the root directory of your website. It should run fine for all desired purposes, no messing about adding code to every page etc.

Expand|Select|Wrap|Line Numbers
  1. <script language="vbscript" runat="server">
  2. Sub Session_OnStart
  3.    Referrer = Request.ServerVariable("HTTP_REFERRER")
  4.    If InStr(Referrer,"http://www.rubbish.com") > 0 Then
  5.       Response.Redirect "http://www.tinyurl.com" 'lol - refer people to the competition?
  6.    End if
  7. End Sub
  8. </script> 
Oct 17 '07 #6
Thank you so much for the explanation and the help,

I have added both (the javascript and the global.asa. I realise that is redundant, but the global.asa seemed to have no effect)

Does this take time to take effect? This is hosted on a godaddy server, if that makes any difference. I know that I have asp running because I have a contact page using an ASP code (and Community Server running as well)

I will keep playing around with it and try to get it to work. I would gladly post the code and show you what I am doing, but then it will no doubt be trawled by the googlebot, and my relative anonymity will be void. If a PM with the actual sites in question would help, I can do that.

We are also in different timezones, so I should have a full day to try and make sense of all of this :)

Thanks again,

Oct 17 '07 #7
OK, why the Java is not working, I don't know. However, it seemed I needed to tick a few godaddy boxes to get the asa working.

Those boxes are ticked now, so it is a matter of waiting for it to sort itself out (hopefully)

I will keep you informed

Oct 17 '07 #8
You know when you have a user that withholds VITAL information from you til right up to the last minute, but you forgive them for it because you are such a great guy and they are clearly clueless? :)

This is running, what I believe to be, ASP.net 2.0

Judging by the fact that Community Server has a global.asax file instead of an asa, and my googling has resulted in the fact they are TOTALLY different, I dare say that greatly affects the code.

As it is now, I have the global.asa, and the global.asa again, renamed to .asax (with more than a little optimism). I have removed the Java, and reconfigured godaddy to make this subdomain of mine be a "content root" and thereby pay attention to this file.

No dice yet, but I am still playing with it.

Is there a point? Is the above solution incompatible with my setup here?

Thanks again

Oct 17 '07 #9
346 Expert 100+
You got it, .asax or .aspx extensions indicate the server is running ASP.Net - however, Both are Microsoft technologies and run on IIS by default (internet information service) - so if you're running ASP.Net chances are your server runs asp as well, unless the server admin has turned it off because godaddy doesn't wish to offer that as a service.

I think you're best shot is to talk to godaddy techsupport and tell them you are trying to implement a global.asa file in classic asp and see if they can help guide you in the right direction. If all else fails you could recode that .asa file into a .net .asax - I don't personally know ASP.Net (yet) but this forum is full of great guys who should be able to help out in that department if it comes down to that. I would talk to godaddy first and see what they say though.

As for the javascript, let me run some tests on it - if it's not working I may have screwed on the syntax.. it looks ok to me but let me take a closer look into it and make sure that it does what it's supposed to.

I'll re-post the new code if the one i posted above doesn't work properly.

Oct 18 '07 #10
346 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. window.onload = checkReferrer;
  2. function checkReferrer() {
  3.    if (document.referrer.indexOf("whatever") > 0) { // change "whatever" to his domain name
  4.       location.href = "goaway.html"; // change this line to where you want the user to be redirected.
  5.    }
  6. }
The original javascript was syntactically incorrect.The mistake was on the first line.. typo. (window.onload - checkReferrer should have been window.onload = checkReferrer)

Anyway, this one works

Hope this helps!

Oct 18 '07 #11

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by Donna Hawkins | last post: by
5 posts views Thread by Trisha | last post: by
1 post views Thread by stevebremermn | last post: by
7 posts views Thread by =?Utf-8?B?YzY3NjIyOA==?= | last post: by
2 posts views Thread by =?ISO-8859-1?Q?Fran=E7ois_de_Dardel?= | last post: by
10 posts views Thread by Eirik Eldorsen | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.