End of htaccess file usage collection and collation _linux

Source: Internet
Author: User
Tags time zones
1. Time zone Settings
Sometimes, when you use the date or Mktime function in PHP, it will show some very strange information because of the different time zones. Here is one way to solve this problem. is to set your server's time zone. You can find a list of all the supported time zones here.
Setenv TZ Australia/melbourne
2. Search Engine Friendly 301 Permanent steering method
Why is this search engine friendly? Because now many modern search engines have the ability to update their existing records based on a permanent turn to check 301.

Redirect Http://www.jb51.net/home http://www.jb51.net/

3. Screen Download dialog box
Typically, when you download something, you see a dialog box asking whether you are keeping the file or opening it directly. If you don't want to see this, you can put the following piece of code in your. htaccess file.
Copy Code code as follows:

AddType Application/octet-stream. pdf
AddType application/octet-stream. zip
AddType Application/octet-stream. mov

4. Omit www prefix
One of the principles of SEO is to make sure that your site has only one URL. Therefore, you need to turn all the access through WWW to non-www, or to reverse this.
Copy Code code as follows:

Rewriteengine on
Rewritebase/
Rewritecond%{http_host} ^www.lvtao.net [NC]
Rewriterule ^ (. *) $ http://lvtao.net/$1 [l,r=301]

5. Personalized error page
Customize your own personalized error page for each error code.
Copy Code code as follows:

ErrorDocument 401/error/401.php
ErrorDocument 403/error/403.php
ErrorDocument 404/error/404.php
ErrorDocument 500/error/500.php

6. Compressed Files
Optimize the speed of your Web site by compressing your file volume.
Copy Code code as follows:

# compress text, HTML, JavaScript, CSS, xml:
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

7. Caching Files
Caching files is another good way to improve the speed of your Web site access.
Copy Code code as follows:

Header set Cache-control "Max-age=2592000″

8. Prohibit the use of caching for certain file types
On the other hand, you can also customize some file types to prohibit the use of caching.
Copy Code code as follows:

# Explicit rules prohibit the use of caching for scripts and other dynamic files
3.Header unset Cache-control

Security Issues
The following htaccess code can improve the security level of your Web server. Image link theft protection is very useful, it can prevent others from stealing the use of your server image resources.

1. Adoption. htaccess put hotlinking
Hate the behavior that steals your bandwidth by stealing picture resources from your Web server? Try this, and you can prevent it from happening.
Copy Code code as follows:

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

2. Anti-hacker
If you want to improve the security level of the site, you can remove the following lines of code, which can prevent some common malicious URL matching hacker attack technology.
Copy Code code as follows:

Rewriteengine on
# Proc/self/environ? No way!
Rewritecond%{query_string} Proc/self/environ [OR]
# block script attempts to modify Mosconfig value via URL
Rewritecond%{query_string} mosconfig_[a-za-z_]{1,21} (=|\%3d) [OR]
# block Base64_encode spam messages that scripts pass through URLs
Rewritecond%{query_string} base64_encode.* (. *) [OR]
# block scripts that contain <\script> tags in URLs
Rewritecond%{query_string} (<|%3c). *script.* (>|%3e) [Nc,or]
# block script that attempts to set PHP's globals variable via URL
Rewritecond%{query_string} GLOBALS (=|[| \%[0-9a-z]{0,2}) [OR]
# block script that attempts to set PHP's _request variable via URL
Rewritecond%{query_string} _request (=|[| \%[0-9a-z]{0,2})
# turn all blocked requests to the 403 Stop prompt page!
Rewriterule ^ (. *) $ index.php [f,l]

3. Block access to your. htaccess file
The following code can prevent someone from accessing your. htaccess file. Similarly, you can also set blocks for multiple file types.
Copy Code code as follows:

# to protect your htaccess files
Order Allow,deny
Deny from all

# prevents viewing of specified files
Order Allow,deny
Deny from all

# Multiple file types
Order Allow,deny
Deny from all

4. Rename htaccess file
You can protect it by renaming the htaccess file.
Copy Code code as follows:

Accessfilename htacc.ess

5. Prohibit Directory browsing
Prevents the server from displaying the directory structure externally and vice versa.
Copy Code code as follows:

# Prohibit Directory browsing
Options all-indexes
# Open Directory Browsing
Options All +indexes

6. Change the default index page
You can change the default index.html, index.php, or index.htm to another page.
Copy Code code as follows:

DirectoryIndex business.html

7. By referencing information to prevent some undesirable visitors
Copy Code code as follows:

# block users from a Web site
Rewriteengine on
Rewritecond%{http_referer} scumbag.com [Nc,or]
Rewritecond%{http_referer} wormhole.com [Nc,or]
Rewriterule. *–[f]

8. To prevent certain requests by judging the browser header information
This method can save you bandwidth by preventing certain robots or spider crawlers from crawling your site.
Copy Code code as follows:

# block users from specific sites
Setenvifnocase ^user-agent$. * (Craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider
|leacher|collector|grabber|webpictures) Http_safe_badbot
Setenvifnocase ^user-agent$. * (Libwww-perl|aesop_com_spiderman) Http_safe_badbot
Deny from Env=http_safe_badbot

9. Prohibit script execution, enhance your directory security
Copy Code code as follows:

# Disable script execution permissions in certain directories
AddHandler cgi-script. php. pl. py. jsp. asp. htm. shtml. Sh.
options-execcgi

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.