Htaccess anti-theft chain, prevent directory browsing and other 10 tips _ server Other

Source: Internet
Author: User
Tags php script
1. Anti-hotlinking
Websites that steal your content and don't want to store pictures themselves are shameless. You can use the following configuration to place someone to steal your picture:
Copy Code code as follows:

Rewritebase/
Rewritecond%{http_referer}!^$
Rewritecond%{http_referer}!^http://(www.)? yoursite.com/.*$ [NC]
Rewriterule. (gif|jpg|swf|flv|png) $/feed/[r=302,l]

2. Prevent Directory browsing
Sometimes directory browsing is useful, but in most cases there are security issues. To make your site more secure, you can disable this feature by htaccess files:
Copy Code code as follows:

Options all-indexes

3. SEO-friendly 301 Permanent redirect
This is a trick I used to use. Every time I change the URL structure of the site, I do 301 redirects:
Copy Code code as follows:

1 Redirect http://www.yoursite.com/article.html http://www.yoursite.com/archives/article

4. Display the personalized 404 error page
When a user accesses a page that does not exist, the Web server displays a "404 File Not Found" error. There are many CMS allows you to set the custom error page, but the easiest way is to change the htaccess:
Copy Code code as follows:

ErrorDocument 404/404.html

5. Set the default page for the directory
If you need to set different default pages for different directories, you can easily pass. htaccess implementation:
Copy Code code as follows:

DirectoryIndex about.html

6. Restrict Web site access based on Referer
Webmasters usually do not restrict site access, but when you find that there are a number of sites to bring you garbage traffic, you should block them:
Copy Code code as follows:

<ifmodule mod_rewrite.c>
Rewriteengine on Rewritecond%{http_referer} spamteam.com [Nc,or]
Rewritecond%{http_referer} trollteam.com [Nc,or]
Rewriterule. *–[f]
</ifModule>

7. Limit php Upload file size
This is useful on a shared-space server, allowing my users to upload larger files. The first is to set the maximum size of the upload file, the second is to set the maximum POST request size, the third PHP script the longest execution time, and the last one is the maximum time that the script resolves the uploaded file:
Copy Code code as follows:

Php_value upload_max_filesize 20M
Php_value post_max_size 20M
Php_value Max_execution_time 200
Php_value Max_input_time 200

8. Compressed Files
You can reduce network traffic by compressing files, and the page load time:
Copy Code code as follows:

Addoutputfilterbytype DEFLATE Text/plain
Addoutputfilterbytype DEFLATE text/html
Addoutputfilterbytype DEFLATE Text/xml
Addoutputfilterbytype DEFLATE Text/css
Addoutputfilterbytype DEFLATE Application/xml
Addoutputfilterbytype DEFLATE Application/xhtml+xml
Addoutputfilterbytype DEFLATE Application/rss+xml
Addoutputfilterbytype DEFLATE Application/javascript
Addoutputfilterbytype DEFLATE Application/x-javascript

9. Caching files
Does this need to be explained?
Copy Code code as follows:

<filesmatch ". (flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf) $ ">
Header set Cache-control "Max-age=2592000″
</FilesMatch>

10. Add Tail backslash
I'm not sure, but many articles, many people say that adding a trailing backslash is beneficial to SEO:
Copy Code code as follows:

<ifmodule mod_rewrite.c>
Rewritecond%{request_uri}/+[^\.] +$
Rewriterule ^ (. +[^/]) $%{request_uri}/[r=301,l]
</IfModule>


use. Htaccess to prevent picture hotlinking

First explain the picture anti-theft chain and turn:

What is the use of picture anti-theft chain?

Prevent other websites from stealing your pictures and wasting your valuable traffic.

What's the use of a picture shift?

If your site to the main picture, which day to find the end of the month did not reach the traffic is running out, then you can use the picture to turn, without modifying the premise of the page, the picture download request to other space (such as trial host), temporary transition.

Let's start with a description, such as your pictures are in the IMG directory, then devolve a file named. htaccess in the directory, which reads as follows:
Copy Code code as follows:

Rewriteengine on

Rewritecond%{http_referer}!^$ [NC]

Rewritecond%{http_referer}!jb51.net [NC]

Rewritecond%{http_referer}!zhuaxia.com [NC]

Rewritecond%{http_referer}!google.com [NC]

Rewritecond%{http_referer}!baidu.com [NC]

Rewritecond%{http_referer}!bloglines.com [NC]

Rewriterule. (jpg|gif|png|bmp|swf|jpeg)/image/replace.gif [r,nc,l]

Rewriterule ^ (. *) $ http:\/\/image.jb51.net\/image\/$1 [L]

Probably explained:
Copy Code code as follows:

Rewritecond%{http_referer}!^$ [NC]

Rewritecond%{http_referer}!jb51.net [NC]

Rewritecond%{http_referer}!zhuaxia.com [NC]

Rewritecond%{http_referer}!google.com [NC]

Rewritecond%{http_referer}!baidu.com [NC]

Rewritecond%{http_referer}!bloglines.com [NC]

This part is to determine whether hotlinking, if the above conditions are set up (that is, access to the picture of the request, neither directly entered the URL, Nor from the jb51.net, nor from the zhuaxia.com, nor from the Google.com, nor from the baidu.com, nor from the bloglines.com, to perform the following turns:
Copy Code code as follows:

Rewriterule. (jpg|gif|png|bmp|swf|jpeg)/image/replace.gif [r,nc,l]

The meaning is to let all hotlinking img directory of JPG, GIF, PNG, BMP, SWF, JPEG files of the Web page, display pictures are replaced with replace.gif pictures in the image directory. Note that replacing the displayed picture is not placed under an IMG directory that sets the anti-theft chain. If the picture request is not hotlinking according to the rules above, perform the following turn:
Copy Code code as follows:

Rewriterule ^ (. *) $ http:\/\/image.jb51.net\/image\/$1 [L]

This means that all requests to the IMG directory are directed to the target server, such as the original URL of a picture. Of course, you have to copy all the files from the original server IMG directory to the image directory of the staging server, and the steering is only really available. The effect is to the original server picture download occupied by the flow of all save, let the temporary server to bear.

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.