If you are a WordPress blogger than must have heard of .htaccess file. The .htaccess stands for “hypertext access” can be found in your root directory of your WordPress blog.
The .htaccess lets admin or webmaster of the blog to manage server configuration, enhancing a site’s performance and security features etc. Using .htaccess you can change the way web server serve your website to visitors. In WordPress blog .htaccess installs by default when you install your WordPress blog.
Wrongly written .htaccess rules can completely mess-up your site, so I recommend you to back up your our existing .htaccess file. If you see anything wrong with your site after using following tutorials, immediately replace with the original htaccess file.

Below are the default WordPress .htaccess rules.
WordPress default .htaccess rules
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPressHere in this article I have posted 15 useful htaccess rules which can be used by WordPress blogger to enhance his blog and increase the performance.
I haven’t tested all of them myself, but these were taken from the popular blogs around the internet and they claim that these were worked as expected.
1. Displaying custom error page using .htaccess
Some WordPress themes contains custom error pages for “404″, “403″ or “500″ errors. If you want to design one yourself and display when perticular error occurs you can do it by using the following code.
You can create custom error page and rename as per the error document.
ErrorDocument 404 /404.php ErrorDocument 403 /403.php ErrorDocument 500 /500.php
2. Block spammers or spam generating from specified IP address
If your blog is targetted by spammers using specified IP address you can block his access to your blog using following .htaccess rule.
allow from all deny from 123.456.78.901
Change “123.456.78.901″ to spammers IP address.
3. Alow only visitors from specified IP address
This .htaccess hack is similar to above one but using this you can allow blog access to specific IP users only. Below .htaccess rule denies access to everyone except users with an IP address of 123.456.789.012 or in the range 123.456.789.xxx. Change the example IP address to the real ones.
orderdeny,allow deny from all allow from 123.456.789.012 allow from 123.456.789
4. Add trailing slash after post url using .htaccess
You can add trailing slash after post url using following .htaccess rule.
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]5. Add expires headers for Images, CSS and JavaScript using .htaccess
WordPress blog’s static content like images, JavaScript and css can be cached in users browsers because they wont change everyday. You can set an expiration time for those images so that the browser to know if the part is still valid or has it expired. Adding expires headers to those static files will help site loading speed of your site.
ExpiresActive On ExpiresDefault "access plus 1 seconds" ExpiresByType image/x-icon "access plus 2692000 seconds" ExpiresByType image/jpeg "access plus 2692000 seconds" ExpiresByType image/png "access plus 2692000 seconds" ExpiresByType image/gif "access plus 2692000 seconds" ExpiresByType application/x-shockwave-flash "access plus 2692000 seconds" ExpiresByType text/javascript "access plus 2692000 seconds" ExpiresByType application/x-javascript "access plus 2692000 seconds" ExpiresByType text/html "access plus 600 seconds" ExpiresByType application/xhtml+xml "access plus 600 seconds" <filesmatch "\\.(ico|jpe?g|png|gif|swf|css|js)$"=""> Header set Cache-Control "max-age=2692000, public" <filesmatch "\\.(ico|jpe?g|png|gif|swf|css|js)$"="" "\\.(x?html?|php)$"="">Header set Cache-Control "max-age=600, private, must-revalidate" Header unset ETag Header unset Last-Modified
6. Remove category slug from a URL
If your category based post displays url like this: http://yourblog.com/category/article/ now you can redirect it to display like this short url: http://yourblog.com/article/ using the .htaccess rule below:
RewriteRule ^category/(.+)$ http://www.yourdomain.com/$1 [R=301,L]
Note: rename http://www.yourblog.com/ to your real domain name.
7. Allow force download of a file instead of opening it in a browser using .htaccess (ex: pdf, mp3, images and text files)
This will be one of the best and handy tweak to .htaccess if you offer files pdf, images, mp3s, videos or text files from your blog. Some files like pdf or images opens is a browser when you click the link, using below .htaccess rule you can let your visitors directly download it.
<filesmatch "\.(mov|mp3|pdf|txt|mpeg)$"=""> ForceType application/octet-stream Header set Content-Disposition attachment
8. Prevent access to .htaccess to your visitors
Below .htaccess rule block any attempts to get access to your .htaccess file. All attempt will result in a 403 error message. In fact, you must protect your .htaccess file using CHMOD to 644 using ftp as a first layer security. [via]
order allow,deny deny from all
9. SEO friendly 301 permanent redirects using .htaccess
If you change the permalink of any article or page and you keep SEO friendly you can do it using .htaccess rule. the following rule in .htaccess file with the old address followed by the new address to keep a page’s SEO rank.
Redirect 301 http://www.mysite.com/article.html http://www.mysite.com/archives/article
10. Stop image hotlink using htaccess rule
So called image hijackers use your images in his site by directly linking from your site. This rises some sort of security concerns and eats up your bandwidth.
To prevent it by adding the following htaccess rule and stop it.
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?mysite.com/.*$ [NC]
RewriteRule .(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]11. Block visitors from certain referring sites using htaccess rule
Any webmaster don’t want to block his visitors. But there are few spam website just allow its user to comment/trackback from his website to any website over the internet. Now you can block those referenced visitors using following htaccess rule.
RewriteEngineon
RewriteCond %{HTTP_REFERER} spammingwebsite.com [NC]
RewriteCond %{HTTP_REFERER} toospammy.spammingwebsite.com [NC]
RewriteCond %{HTTP_REFERER} morespams. [NC]
RewriteRule .* - [F]12. Setting server admin default email address using htaccess
ServerSignature EMail SetEnv SERVER_ADMIN default@domain.com
13. 301 Redirect from old domain to a new domain
#Redirect from an old domain to a new domain RewriteEngine On RewriteRule ^(.*)$ http://www.domainname.com/$1 [R=301,L]
14. Enabling Gzip using htaccess
Enabling Gzip increases site loading speed of your blog. Following htaccess rule will help you to enabling Gzip for supporting browsers.
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript 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
15. Remove www from URL
There are two types of rules you can use to strip www from your domain name, use only one of the below:
Rule type 1
#remove www from url
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]Rule type 2
# Redirect if www.yourdomain.com to yourdomain.com
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]












I thought I have done good experiment on .htaccess. Thanks buddy for valuable sharing..