Htaccess: Preventing hot linking: Difference between revisions

From The Uniform Server Wiki
Jump to navigation Jump to search
No edit summary
(Moved to new category; Additional grammar and cleanup edits.)
 
(2 intermediate revisions by 2 users not shown)
Line 2: Line 2:
<div style="padding:0;margin:0; border-bottom:3px inset #000000">
<div style="padding:0;margin:0; border-bottom:3px inset #000000">
{|  
{|  
|[[Image:uc_small_logo.gif | MPG UniCenter]] ||
 
.htaccess:  
.htaccess:  
[[Htaccess: Introduction | Introduction]] |   
[[Htaccess: Introduction | Introduction]] |   
Line 20: Line 20:
'''Hot linking'''
'''Hot linking'''


What is hot linking? Its when someone links to content on your server and uses your server to deliver the goods. It could be images or any non html objects, they are effectively stealing your bandwidth at you expense.
What is hot linking? It's when someone else links to some content on your server and uses your server to deliver the goods. It could be images or any non-html objects. They are effectively stealing your bandwidth at your expense.


Uniform Server has mod-rewrite enabled, allowing you to rewrite the requested URL on-the-fly based on configuration directives and rules. Yep it as complex as it sounds. I found this code on the Internet it prevents hot linking to images on your site.
The Uniform Server has mod-rewrite enabled, allowing you to rewrite the requested URL on-the-fly based on configuration directives and rules. It's as complex as it sounds. I found this code on the Internet which prevents hot linking to images on your site.


Just pop this code into your root htaccess file for global effect or a sub-folder to localise the effect to just one section of your site:
Just pop this code into your root .htaccess file for global effect, or a sub-directory to localise the effect to just one section of your site:


== Serve a broken image ==
== Serve a broken image ==
This code produces a broken image to be displayed when its hot linked. Make sure to replace "mydomain.com" with your own.  
This code produces a broken image to be displayed when it's hot linked. Make sure to replace "mydomain.com" with your own.  
<pre>
<pre>
Options +FollowSymLinks
Options +FollowSymLinks
Line 47: Line 47:


== Serve an alternative image ==
== Serve an alternative image ==
I keep telling you its your server and you can do what you like so why not server an alternative image in your favor again remember to replace "mydomain.com" with your own:
Remember, it's your server and you can do what you like, so why not serve an alternative image in your favor. Again, remember to replace "mydomain.com" with your own:


<pre>
<pre>
Line 58: Line 58:


== General note ==
== General note ==
I have seen several cases where mod rewrite is used in htaccess files and the line
I have seen several cases where mod rewrite is used in .htaccess files and the line


'''Options +FollowSymLinks'''
'''Options +FollowSymLinks'''


is missing which effectively informs Apache to ignore mod_rewrite.
is missing, which effectively informs Apache to ignore mod_rewrite.


This error shows up in the log files as:
This error shows up in the log files as:
Line 71: Line 71:
|}
|}


Apache log files are located in folder: '''*\Uniform Server\udrive\usr\local\apache2\logs'''
 
 
'''''[[#top | Top]]'''''
----
----


{|
[[Category: Apache Configuration]]
| [[Image:uc_small_logo.gif]] || [[User:Ric|Ric]]
|}
 
[[Category: UniCenter]]
[[Category: Support]]
[[Category: Troubleshooting ]]
[[Category: Application]]
[[Category: Development]]
==Related Links:==
 
[http://www.freesampleagent.com/'''free samples''']

Latest revision as of 11:50, 21 June 2013

.htaccess: Introduction | Site error documents | Prevent Directory Listing | Redirect | Preventing hot linking |

.htaccess - Apache directory-level configuration file

Hot linking

What is hot linking? It's when someone else links to some content on your server and uses your server to deliver the goods. It could be images or any non-html objects. They are effectively stealing your bandwidth at your expense.

The Uniform Server has mod-rewrite enabled, allowing you to rewrite the requested URL on-the-fly based on configuration directives and rules. It's as complex as it sounds. I found this code on the Internet which prevents hot linking to images on your site.

Just pop this code into your root .htaccess file for global effect, or a sub-directory to localise the effect to just one section of your site:

Serve a broken image

This code produces a broken image to be displayed when it's hot linked. Make sure to replace "mydomain.com" with your own.

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

Or

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?(subdomain_mydomain\.)?mydomain.com/ [NC]
RewriteRule \.(jpe?g|gif|png|bmp)$ - [F] 

Link: I think the original source came from here: webmasterworld.com

Serve an alternative image

Remember, it's your server and you can do what you like, so why not serve an alternative image in your favor. Again, remember to replace "mydomain.com" with your own:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.mydomain.com/nasty.gif [R,L]

General note

I have seen several cases where mod rewrite is used in .htaccess files and the line

Options +FollowSymLinks

is missing, which effectively informs Apache to ignore mod_rewrite.

This error shows up in the log files as:

[client 127.0.0.1] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: W:/www/textpattern/