1. Time Zone settings
Sometimes, when you use the date or mktime function in PHP, it will display some strange information due to different time zones. The following is one of the solutions to this problem. Is to set the time zone of your server. You can find a list of all supported time zones here.
SetEnv TZ Australia/Melbourne
2. Search Engine-friendly 301 permanent redirection Method
Why is this search engine friendly? Because many modern search engines now have the ability to update their existing records permanently based on check 301.
Redirect 301 http://www.jb51.net/home http://www.jb51.net/
3. Download blocking dialog box
Generally, when you download a file, you will see a dialog box asking whether you want to keep the file or open it directly. If you don't want to see this, you can put the following code in your. htaccess file.Copy codeThe Code is as follows: AddType application/octet-stream. pdf
AddType application/octet-stream. zip
AddType application/octet-stream. mov
4. Eliminate www prefix
One principle of SEO is to ensure that your website has only one URL. Therefore, you need to turn all the access via www to non-www, or reverse this.Copy codeThe Code is as follows: RewriteEngine On
RewriteBase/
RewriteCond % {HTTP_HOST} ^ www.lvtao.net [NC]
RewriteRule ^ (. *) $ http://lvtao.net/1121 [L, R = 301]
5. Personalized Error page
Customize custom error pages for each error code.Copy codeThe Code is 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
By compressing your file volume, you can optimize the Website access speed.Copy codeThe Code is as follows: # compress text, html, javascript, css, and 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. cache files
Caching files is another good way to speed up your website access.Copy codeThe Code is as follows: Header set Cache-Control "max-age = 2592000 ″
8. Disable caching for certain file types
On the other hand, you can also disable caching for certain file types.Copy codeThe Code is as follows: # explicitly prohibit the use of cache for scripts and other dynamic files
3. Header unset Cache-Control
Security Questions
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 using the image resources on your server.
1. Put leeching through. htaccess
Hate the image resources on your web server that steal links and consume your bandwidth? You can try this to prevent this from happening.Copy codeThe Code is 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 your website, you can remove the following lines of code to prevent hacker attack techniques that match common malicious URLs.Copy codeThe Code is as follows: RewriteEngine On
# Proc/self/environ? No!
RewriteCond % {QUERY_STRING} proc/self/environ [OR]
# Prevent the script from attempting to modify the mosConfig value through URL
RewriteCond % {QUERY_STRING} mosConfig _ [a-zA-Z _] {} (=|\% 3D) [OR]
# Block base64_encode junk information transmitted by a script through a URL
RewriteCond % {QUERY_STRING} base64_encode. * (. *) [OR]
# Block scripts whose URL contains the <\ script> flag
RewriteCond % {QUERY_STRING} (<| % 3C). * script. * (>|% 3E) [NC, OR]
# Block scripts that attempt to set the GLOBALS variable of PHP through URL
RewriteCond % {QUERY_STRING} GLOBALS (= | [| \ % [0-9A-Z] {0, 2}) [OR]
# Block scripts that attempt to set the PHP _ REQUEST variable through URL
RewriteCond % {QUERY_STRING} _ REQUEST (= | [|\% [0-9A-Z] {0, 2 })
# Redirect all blocked requests to the 403 Forbidden prompt page!
RewriteRule ^ (. *) $ index. php [F, L]
3. block access to your. htaccess File
The following code prevents others from accessing your. htaccess file. You can also block multiple file types.Copy codeThe Code is as follows: # Protect Your htaccess File
Order allow, deny
Deny from all
# Block viewing of specified files
Order allow, deny
Deny from all
# Multiple File Types
Order Allow, Deny
Deny from all
4. Rename the htaccess File
You can rename the htaccess file to protect it.Copy codeThe Code is as follows: AccessFileName htacc. ess
5. Disable directory browsing
Disable the server from displaying the directory structure externally, and vice versa.Copy codeThe Code is 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 codeThe Code is as follows: DirectoryIndex business.html
7. Block some undesirable viewers by referencing informationCopy codeThe Code is as follows: # block users from a website
RewriteEngine on
RewriteCond % {HTTP_REFERER} scumbag.com [NC, OR]
RewriteCond % {HTTP_REFERER} wormhole.com [NC, OR]
RewriteRule. *-[F]
8. Some requests are blocked by judging the browser header information
This method can save your bandwidth traffic by preventing some robots or spider crawlers from crawling your website.Copy codeThe Code is as follows: # block users from certain websites
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 to enhance your Directory SecurityCopy codeThe Code is as follows: # prohibit the script execution permission in some Directories
AddHandler cgi-script. php. pl. py. jsp. asp. htm. shtml. sh. cgi
Options-ExecCGI