Simple Apache to prevent hotlinking

Source: Internet
Author: User

Intermediary transaction http://www.aliyun.com/zixun/aggregation/6858.html ">seo diagnose Taobao guest cloud host technology Hall

Hotlinking (hotlinking) is a headache, when we upload a file to our own Web server, others link to the file and use our bandwidth to display or distribute the file directly on his website. Download files that most often occur in pictures such as links, zip, and PDF.

The best way to block others ' hotlinking on the Apache host is to create a htaccess file for your files so that you can protect your files and all subdirectories will be protected. Before attempting this feature, make sure your webhosting can use the. htaccess file.

To use it you can simply upload a. htaccess to your site's directory.

Let's edit it with the following steps:

Rewriteengine on

Rewritecond%{http_referer}!^$

Rewritecond%{http_referer}!^http (s)?:/ /(www\.)? havefirst.com [NC]

Rewriterule. (jpg|jpeg|png|gif) $-[nc,f,l]

Of course, you have to edit your own domain name above, and add other file formats in column fourth. If you have other domain names, you can allow hotlinking your files, you can simply add to the third column, and the corresponding change the domain name.

The. htaccess file itself affects its root directory and its subdirectories. Therefore, if the content we want to protect (to prevent the picture as an example) is located in multiple directories within the site, consider placing it in the root directory, and if the picture has a separate subdirectory, such as "/images/", Just place it in the directory.

If you want to not only allow hotlinking to hotlinking hotlinking content but also display a few warning messages, you can create a picture that contains text such as "Havefirst pictures, no hotlinking," but in order to achieve the main purpose of saving bandwidth, the picture should be small enough to make the picture- Upload to the site's root directory or the site subdirectory that this. htaccess file wants to protect, such as "http://www.havefirst.com/warning.gif," and then change line fourth above to read:

Rewriterule. (gif|jpg) $ http://www.havefirst.com/warning.gif [r,l]

And in WordPress blog can not be used. htaccess, but the WordPress plugin could be used hotlink homeowner, which basically played the same role, but could not allow additional domain names.

In addition, htaccess can do a lot of things, including: folder password protection, user automatic redirection, custom error page, change your file name extension, block specific IP address users, only allow specific IP address users, prohibit directory listings, and use other files as index files.

Sometimes creating a. htaccess file may bring us some difficulties. It's easy to write a file, just write the appropriate code in a word editor. And the real difficulty may be in the preservation of the file, because. htaccess this bizarre file name (it actually doesn't have a filename, just a 8-letter extension).

Such a file name cannot be accepted in some systems, such as Windows 3.1. What we need to do in most operating systems is to save the name of the document as: ". htaccess" (including quotes). If still not, then we need to name the precursors other names (such as Htaccess.txt), and then upload the modified files to the server, and then directly with the FTP software to rename. When I tested, I created a new "text document" under Windows Server 2003 that was successfully saved as ". htaccess" (including quotes saved).

Attachment:. htaccess tool Connection

Online. htaccess File Builder

http://cooletips.de/htaccess/can be generated online. htaccess files, very simple to configure redirection, system error files, and so on.

. htaccess Editor Online Editor

Customizable default encoding, error page, etc.

Download Address: Http://9458398.cn/attachments/month_0506/zxp4_my.rar

More references. htaccess information:

http://parandroid.com/htaccess-guide-to-the-use-of-two-documents-httacces-document-configuration/

This article originates from: http://www.havefirst.com/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.