Hotlinking to Html pages

S

snorkerz

I'd like customers to only link to my pages from within the website, ie
not from links or with direct urls. The only one to allow access from
outside should be the home page.

I am not sure if .htaccess or javascript is the way to go - could
anyone offer a suggestion / solution?

Thanks

Benji the dog
 
D

Dylan Parry

Pondering the eternal question of "Hobnobs or Rich Tea?",
(e-mail address removed) finally proclaimed:
I'd like customers to only link to my pages from within the website, ie
not from links or with direct urls. The only one to allow access from
outside should be the home page.

You can do this with .htaccess, but it isn't very reliable. The main
problem that you will come across is that some user agents won't send a
referrer when requesting a page, so they will *always* be redirected to
your homepage.

To be honest, I can't see /why/ you are trying to do this? Could you
explain your rationale so that we could perhaps suggest something
better?
 
S

snorkerz

No, I've no idea why either....

I have offered to build some websites for people so that I can expand
my knowledge of HTML etc, and this is one of the ones I've put
together.

I have seen a javascript which will redirect depending on referrer -
just not sure if I could use it to refer all enquiries to the home page
without including every single page on the site in the script? (also, I
think .htaccess will be tidier). So far as reliability is concerned -
I'm not too worried, as the site neither holds 'confidential' stuff and
nor will it generate huge traffic.

The script is:

<script language="javascript">
//by www.a1javascripts.com/
<!--
var name = (""+ document.referrer +"" )
if (name ==
"http://www.a1javascripts.com/redirection_scripts/index.html") {
url=(""+ document.referrer +"");
}
else if (name ==
"http://a1javascripts.com/redirection_scripts/index.html") {
url=(""+ document.referrer +"");
}
else if (name == "http://www.a1javascripts.com/redirection_scripts/") {
url=(""+ document.referrer +"");
}
else if (name == "http://a1javascripts.com/redirection_scripts/") {
url=(""+ document.referrer +"");
}
else {

url=("http://www.a1javascripts.com/");
}
document.write('<A HREF="' + url + '">This Link</A>');
//-->
</script>
 
A

Andy Dingley

I'd like customers to only link to my pages from within the website, ie
not from links or with direct urls. The only one to allow access from
outside should be the home page.

Your first sentence is almost meaningless. I assume that what you
really want is

"Any links from the outside world to my site should be redirected to
the homepage"

This is crazy, but fairly possible. It's your site after all.
I am not sure if .htaccess or javascript is the way to go - could
anyone offer a suggestion / solution?

..htaccess is definitely the way to go. JavaScript is a bad idea in
several ways and it doesn't solve the oneproblem .htaccess suffers
from.

There are five cases you need to deal with, all based on testing the
HTTP Referer (search for a .htaccess tutorial on the details):

- A referrer from your own site: Do nothing, just let the page be
served.

- A referrer from another site. Redirect to your homepage.

- Any request for your homepage, with any referrer. DO NOT redirect,
otherwise you risk redirection loops.

Now the tricky stuff!

- A blank referrer, because it's a direct access or a bookmark, not a
link. You might think you should redirect here.

- A blank referrer, because the user agent doesn't support them. Do
you redirect (locking such users permanently into a single page of your
site) or do you not redirect (allowing referer-less agents to link
wherever they wish).

The trouble is that you can't tell the last two cases apart, which
means that taking the second approach to case 5 also turns off case 4.
This means that you either have to make the site unusable for
referer-less agents, or you forbid linking from outside but still
permit bookmarking.

Quite honestly the whole idea is a bad one. Locking out linking is bad
enough, but locking out bookmarks is even worse.


Why do dezyners still think that offending users is ever a good idea?
 
C

confused

Thanks for that Andy.

No, I can't see the point either, though I've emailed the 'customer' to
find out.

I have some very basic .htaccess knowledge so I'll be looking for the
tutorial you suggested and reading it in conjunction with your
comments.

In the mean time...

anyone got a suitable bit of .htaccess I could pinch? :)
 
N

Nick Theodorakis

confused said:
Thanks for that Andy.

No, I can't see the point either, though I've emailed the 'customer' to
find out.

How will your customer like search engines crawlers to be redirected
away to the home page? People searching for info on his site might never
find it on google.

Nick
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top