| TOP 13 .htaccess Essential Tricks For Blog/Website |
|
|
| Автор Administrator | ||||
| 27.06.2009 г. | ||||
Data CompressionUse this code to compress data at web server. Data compression can minimize resources and bandwidth you consume while your website browsing. # data compressionAddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css application/javascript GZip Data CompressionFollowing is GZIP Compression code. More effective. You can specify which files to compress. # gzip compression<IfModule mod_gzip.c> mod_gzip_on Yes mod_gzip_dechunk Yes mod_gzip_item_include file \.(html?|txt|css|js|php|pl|jpg|png|gif)$ mod_gzip_item_include handler ^cgi-script$ mod_gzip_item_include mime ^text/.* mod_gzip_item_include mime ^application/x-javascript.* mod_gzip_item_exclude mime ^image/.* mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*</IfModule> Preserve BandwidthPreserve bandwidth using this method. This is also a compression method. # preserve bandwidth<ifmodule mod_php4.c> php_value zlib.output_compression 16386</ifmodule> Cache ControlCache is very very useful. By using following code in .htaccess you can enable cache of your files. When enabling cache you will see significant increase in website load time. You will be really amazed to see heavy pages and images loading very fast. # Begin Cache Control<IfModule mod_expires.c>ExpiresActive OnExpiresByType application/x-javascript A2592000ExpiresByType text/css A2592000ExpiresByType image/gif A604800ExpiresByType image/png A604800ExpiresByType image/jpeg A604800</IfModule> Secure .htaccess fileDeny .htaccess file to all intruders. You can specify more files which you want to protect by seperating file names by | sign. .htaccess file can have potential information which must be secured from all outside intruders. # secure htaccess file<Files .htaccess> order allow,deny deny from all</Files> Secure DirectoriesBy default your web server’s indexes are on. That means the directory with no index file in it will display all the files in it. Do you want the files in your wp-admin, wp-includes, images, uploads, themes, plugins folders to be seen? It is really not a good idea to show your online folder files. By using following code you will enable protection for all online directories with no index file and will not display files in them. # No directory listing across domainOptions -Indexes Secure Hidden Files at ServerHidden files can be server configuration files, log files and other server reserved files which should be protected from hackers as well. # Disallow hidden filesRedirectMatch 403 /\..*$ Stop HotlinkingSome webmasters will just copy the path of images and other media from your website and use that in their own website to display your content consuming your bandwidth. This method is called as hotlinking. Protect hotlinking by using the following code. sorry.gif in the following example is the alternative file which will be displayed when someone will try and steal your content.
# stop hotlinking and serve alternate contentRewriteEngine OnRewriteCond %{HTTP_REFERER} !^$RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourservernamehere.com/RewriteRule \.(gif|jpg)$ http://www.yourservernamehere.com/sorry.gif [R,L]
Secure Contact FormsSecure your contact form from bots and automated softwares which will email you spam. Change ‘contact.php’ page name to your contact page name.
# secure contact formsRewriteCond %{HTTP_REFERER} !^http://www.yourservernamehere.com/.*$ [NC]RewriteCond %{REQUEST_POST} .*contact.php$RewriteRule .* - [F]
Redirect Error PagesHave you ever encountered 500 error. Internal Server error. That’s really ugly black and while page. I would suggest you to create your own custom error pages and use them wisely to make users stay at your website even some error occurs. Use the following code to redirect the users to your custom error pages in case some error occurs. <IfModule mod_rewrite.c>RewriteEngine OnErrorDocument 206 http://www.yourservernamehere.com/maintenance-mode.htmlErrorDocument 400 http://www.yourservernamehere.com/maintenance-mode.htmlErrorDocument 408 http://www.yourservernamehere.com/maintenance-mode.htmlErrorDocument 500 http://www.yourservernamehere.com/maintenance-mode.htmlErrorDocument 404 http://www.yourservernamehere.com/404.html</IfModule> Disable ETagsDisabling Etags will also increase website speed a bit. Removing ETags is a very safe option. # disable etagsFileETag none Enable Simple Mod RewriteThis is not a performance tip. This is how you enable rewriting at your server. I will write a guide about Mod Rewriting in next .htaccess post. # enable basic rewritingRewriteEngine on Instruct Browser to Download Multimedia Files - Force DownloadIf you want to tell the browser to download certain file types then use the following code. # instruct browser to download multimedia filesAddType application/octet-stream .aviAddType application/octet-stream .mpgAddType application/octet-stream .wmvAddType application/octet-stream .mp3 In the end let m give you two beautiful resources about .htaccess. Рекомендуйте этот пост своим знакомым... Добавить в любимые (59) | Просмотров: 1055
Только зарегистрированные пользователи могут оставлять коментарии. |
||||
| « Пред. | След. » |
|---|




Ключи для NOD32


