Forum Moderators: phranque

Message Too Old, No Replies

Redirection using .htaccess

         

BrutusGutten

9:10 am on Dec 5, 2006 (gmt 0)

10+ Year Member



Hi Guys,

I am new to this forum and I know very little about .htaccess.

I run a successful website, and as a result of that there are several other webmasters who "deep-link" or "leech" on to my pages giving the impression that they are part of their own websites. I have no wish to block these links but I would like to redirect them to the "index" page of my site so that the interested parties are aware that they have been forwarded to another site and can browse it if they wish. This would apply to all .html pages and various download pages in .doc and .pdf format.

I am told that this can be done using my .htaccess file. Can anybody please direct me to such a script or help me in any way?

Thanks in advance.

jdMorgan

2:38 pm on Dec 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is similar to HTTP Referrer-based hotlinking prevention. A search on those words will likely turn up lots of information on the subject. There is no 'generic' code for this, because you must adapt the concept to your individual page names and server configuration. Therefore, you will have to have a basic understanding of the code itself and how to modify it.

The basic idea is:


RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^(www\.)?example\.com
RewriteRule ^deep_linked_page\.html$ http://www.example.com/category_page.html [R=301,L]

You'll likely need to modify many things about that example, and be aware that it only works if the client provides an HTTP referrer header -- and many don't. Therefore, it won't be 100% effective. However, it may be effective enough to convince the other sites' Webmasters to stop deep-linking. Or they might stop linking completely. Only you can decide if that would be good or bad. So, this is not at all just a technical question...

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim