You may have been working on a website, or reading an article about web development, and heard about the .htaccess file,
but wondered what it was, or what, if anything, you can do with it.
This tutorial will tell you the basics about .htaccess, and show you a few ways to secure your wordpress website from hackers
1 2 3 4 5 6 7 8 | <Limit GET POST PUT> order allow,deny allow from all deny from 123.456.789 deny from 93.121.788 deny from 223.956.789 deny from 128.456.780 </LIMIT> |
1 2 3 4 | RewriteEngine on RewriteCond %{REQUEST_URI} !/maintenance.html$ RewriteCond %{REMOTE_ADDR} !^123.123.123.123 RewriteRule $ /maintenance.html [R=302,L] |
1 2 3 4 5 6 7 8 | RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www.yourblogname.com [NC] RewriteRule ^(.*)$ http://yourblogname.com/$1 [L,R=301] RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^yourblogname.com [NC] RewriteRule ^(.*)$ http://www.yourblogname.com/$1 [L,R=301] |
The following htaccess code won’t help the initial page load, but it will significantly help subsequent page loads by sending 304 statuses when requested elements haven’t been modified.
1 2 3 | FileETag MTime Size ExpiresActive on ExpiresDefault "access plus x seconds" |
Allow only your IP address to access administrator area of your website. This will help you from hackers to hack your website. Copy paste code in your .htaccess file and upload it to root directory of website.
1 2 3 4 5 6 7 8 9 | AuthUserFile /dev/null AuthGroupFile /dev/null AuthName "Wordpress Admin Access Control" AuthType Basic <LIMIT GET> order deny,allow deny from all allow from xx.xx.xx.xx </LIMIT> |
1 2 3 4 5 6 | ## USER IP BANNING <Limit GET POST> order allow,deny deny from 200.49.176.139 allow from all </Limit> |
1 2 3 4 5 | # protect wpconfig.php <files wp-config.php> order allow,deny deny from all </files> |
Is your website taking more time to load, if yes, copy paste below code in your .htaccess file. Below code will enable gzip compression for your website, which will reduce web page loading time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # 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 AddType x-font/otf .otf AddType x-font/ttf .ttf AddType x-font/eot .eot AddType x-font/woff .woff AddType image/x-icon .ico AddType image/png .png |
If you want to redirect your old domain to new domain, then create .htaccess file on root of your website and copy paste below code.
1 2 3 | Options +FollowSymLinks RewriteEngine on RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] |
10- GZip compression
1 2 3 4 5 6 | <IfModule mod_deflate.c> AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/x-javascript BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html </IfModule> |
Please don’t forget to share and subscribe to latest updates of the blog. Comments and feedbacks are always welcome! Thanks!
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: GZip compression using htaccess, how to fix canonical error, htaccess, wordpress, wordpress GZip compression