3

We have a landing page which is used only for running an ad campaign. There is a website that has found this link somehow and is linking to it. I've been told by marketing they don't want that website linking to the landing page. How can I prevent a specific website from linking to our domain? I don't want to block all websites from linking to it, just this specific one. Is there solution something to do with .htaccess? If so, please provide an example of doing this or a link to example because I've been unable to find one.

1
  • Marketing doesn't want it linked to, because it's part of an ad campaign as I stated. Which means it will have a special call to action and contain information out of context and will confuse those that visiting the website that didn't come there from the ad. This is not censorship anymore than preventing people from knowing what a temporary phone number is for tracking so they don't think it's the MAIN phone number.
    – Edward
    Mar 17, 2013 at 4:58

2 Answers 2

10

You can't stop a site linking to you with technical measures, but you can identify requests which have come from that site/url and block these in .htaccess -

RewriteEngine on
RewriteCond%{HTTP_REFERER} ^http://www\.site\.com [NC]
RewriteRule index.html   http://www.go-away.com/goaway.html [R]

The above rules will probably need some tweeking, but the idea is to match the REFERER (yes, that spelling is correct) - in this case where the referer starts with http://www.site.com - and then if they land on index.html redirect them to the url goaway.html)

If you REALLY want to attempt to stop them from linking to you, I'd suggest finding out who they are and getting a lawyer to write a letter. Then follow it up with legal action if you can find grounds to.

2
  • 2
    Sites that get a lot of traffic can cost a lot of money in bandwidth as well as skewed perspectives of a cause. A locked door keeps a honest man honest.
    – kobaltz
    Mar 17, 2013 at 4:34
  • 3
    @kobaltz - I respectfully disagree. Trying to prevent someone from linking to your site is akin to saying to them they are not allowed to say certain things (because all a link is doing is saying look over there). Preventing someone from creating this link is censorship - something which is not compatible with a healthy Internet. [Hence why I suggest a technical measure to distance yourself from the site or drop the traffic from people with that referer ]
    – davidgo
    Mar 17, 2013 at 4:50
1

http://www.javascriptkit.com/howto/htaccess10.shtml

In the webmaster community, "hot linking" is a curse phrase. Also known as "bandwidth stealing" by the angry site owner, it refers to linking directly to non-html objects not on one own's server, such as images, .js files etc. The victim's server in this case is robbed of bandwidth (and in turn money) as the violator enjoys showing content without having to pay for its deliverance. The most common practice of hot linking pertains to another site's images.

Using .htaccess, you can disallow hot linking on your server, so those attempting to link to an image or CSS file on your site, for example, is either blocked (failed request, such as a broken image) or served a different content (ie: an image of an angry man) . Note that mod_rewrite needs to be enabled on your server in order for this aspect of .htaccess to work. Inquire your web host regarding this.

With all the pieces in place, here's how to disable hot linking of certain file types on your site, in the case below, images, JavaScript (js) and CSS (css) files on your site. Simply add the below code to your .htaccess file, and upload the file either to your root directory, or a particular subdirectory to localize the effect to just one section of your site:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg|js|css)$ - [F]

Be sure to replace "mydomain.com" with your own. The above code creates a failed request when hot linking of the specified file types occurs. In the case of images, a broken image is shown instead. Serving alternate content when hot linking is detected

You can set up your .htaccess file to actually serve up different content when hot linking occurs. This is more commonly done with images, such as serving up an Angry Man image in place of the hot linked one. The code for this is:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/angryman.gif [R,L]
2
  • 4
    This won't even work for this situation. This is for preventing hotlinking, not for preventing links to the full page from another site.
    – nhinkle
    Mar 17, 2013 at 6:31
  • This was the most helpful and provided a very useful link.
    – Edward
    Mar 17, 2013 at 7:38

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.