Apache's. htaccess file is the heart of the server, controlling the various rules of access to the site. Here are 11 nice, htaccess clips that can help you optimize your site, including redirection, performance, usability, and more!
1. Force suffix back slash
At the end of the URL plus a backslash seems to be beneficial to SEO:)
<ifmodule mod_rewrite.c>
rewritecond%{request_uri}/+[^\.] +$
rewriterule ^ (. +[^/]) $%{request_uri}/[r=301,l]
</IfModule>
2. Anti-Theft Chain
Save your precious bandwidth!
01.RewriteEngine on
#Replace mysite\.com/with your blog URL
03.RewriteCond%{http_referer}!^http://(. +\.)? mysite\.com/[NC]
04.RewriteCond%{http_referer}!^$
#Replace/images/nohotlink.jpg with your "don ' t hotlink" image URL
06.RewriteRule. *\. (jpe?g|gif|bmp|png) $/images/nohotlink.jpg [L]
3. REDIRECT Mobile devices
Join your website to support mobile device access, it is best to redirect mobile device access to a specially customized page
Rewriteengine on Rewritecond%{request_uri}!^/m/.*$ rewritecond%{http_accept} "Text/vnd.wap.wml|application/vnd.wap . Xhtml+xml "[Nc,or] Rewritecond%{http_user_agent}" acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew| Cell|cldc|cmd-"[Nc,or] Rewritecond%{http_user_agent}" dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno| Lg-c|lg-d|lg-g|lge-"[Nc,or] Rewritecond%{http_user_agent}" maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-| NEWT|NOKI|OPWV "[Nc,or] Rewritecond%{http_user_agent}" palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap| Sage|sams|sany "[Nc,or] Rewritecond%{http_user_agent}" sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony| Sph-|symb|t-mo "[Nc,or] Rewritecond%{http_user_agent}" teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa| Wapi "[Nc,or] Rewritecond%{http_user_agent}" wapp|wapr|webc|winw|winw|xda|xda-"[Nc,or] Rewritecond%{HTTP_USER_AGEN T} "UP.BROWSER|UP.LINK|WINDOWSSCE|IEMOBILE|MINI|MMP" [Nc,or] Rewritecond%{hTtp_user_agent} "SYMBIAN|MIDP|WAP|PHONE|POCKET|MOBILE|PDA|PSP" [NC] #-------------The line below excludes the IPad Re Writecond%{http_user_agent}!^.*ipad.*$ #-------------Rewritecond%{http_user_agent}!macintosh [NC] #*SEE Note BELO W rewriterule ^ (. *) $/m/[l,r=302]
4. Force the browser to download the specified file type
You can force browsers to download certain types of files, rather than reading and opening them, such as MP3, XLS.
<files *.xls>
forcetype application/octet-stream
Header set content-disposition attachment
</ files>
<files *.eps>
forcetype application/octet-stream
Header set content-disposition Attachment
</Files>
5. Firefox's cross domain font embedding
Firefox does not allow embedding an outer-station font, the following. htaccess fragment can bypass this restriction
<filesmatch "\. (Ttf|otf|eot|woff) $ ">
<ifmodule mod_headers.c>
Header set Access-control-allow-origin" http:// YourDomain.com "
</IfModule>
</FilesMatch>