Simple configuration. 10 features that htaccess can achieve

Source: Internet
Author: User
Tags php script

Customers are often consulted on the red Host 301 How to configure, the default home page How to configure, how to prohibit directory browsing and so on, because the red host is the Linux operating system, the use of the server is Apache, So the customers mentioned these issues are through the. htaccess file to achieve the effect, so, excerpts from the Internet some. htaccess commonly used configuration files.

1. Anti-hotlinking

Websites that steal your content and don't want to store images on their own are common. You can use the following configuration to place someone else to steal your image:

Rewritebase /Rewritecond %{Http_referer} !^$Rewritecond %{Http_referer} !^http://(www.) bossidc.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 is a security issue. To make your site more secure, you can disable this feature through the htaccess file:

OptionsAll-Indexes 
3. Seo-friendly 301 Permanent redirect

This is a trick I used to use. Every time I change the site URL structure, I do 301 redirects:

rewriteengine    on    rewritecond     %{ http_host  }    !^  www   BOSSIDC   com$  [ nc  ]    rewriterule    ^ (. *)  $ http  :  //www.bossidc.com/$1 [l,r=301]  

4. Display the personalized 404 error page

when a user accesses a page that does not exist, the Web server displays the "404 File Not Found" error. There are many CMS that allow you to set a custom error page, but the simplest way is to change the htaccess:

ErrorDocument404/404.html


5. Set the default page of the directory if you need to set different default pages for different directories, you can easily pass the. htaccess implementation :

DirectoryIndex  About . HTML

6. Restrict website access based on Referer

webmasters usually do not restrict access to websites, but when you find that some sites are giving you garbage traffic, you should block them:

<ifmodulemod_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 server in a shared space, allowing my users to upload larger files. The first is to set the maximum upload file size, the second is to set the maximum POST request size, the third PHP script the longest execution time, the last is the script to parse the maximum time to upload the file :
20M 20M
8. Compress files You can reduce network traffic by compressing files, page loading time:
 AddoutputfilterbytypeDEFLATE Text/PlainAddoutputfilterbytypeDEFLATE Text/HTMLAddoutputfilterbytypeDEFLATE Text/XMLAddoutputfilterbytypeDEFLATE Text/CSSAddoutputfilterbytypeDEFLATE Application/XMLAddoutputfilterbytypeDEFLATE Application/XHTML+XMLAddoutputfilterbytypeDEFLATE Application/RSS+XMLAddoutputfilterbytypeDEFLATE Application/JavaScriptAddoutputfilterbytypeDEFLATE Application/x-JavaScript
9. Caching files Do you need to explain this?
<filesmatch". ( Flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf) $ ">Header set Cache-control" max-age=2592000 " </FilesMatch>
10. Add trailing backslashes I'm not sure, but a lot of articles, many people say adding trailing backslashes is beneficial for SEO:
<ifmodulemod_rewrite. C > Rewritecond%{request_uri}/+[^\.] + $RewriteRule ^ (. +[^/]) $%{request_uri}/[r=301,l]</IfModule>

Source: >  

From for notes (Wiz)

Simple configuration. 10 features that htaccess can achieve

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.