A – WP- Admin
Your can restrict access to wp-admin by IP:
1.order deny,allow2.allow from a.b.c.d # This is your static IP3.deny from allSource - BlogSecurity.net
B – Blacklist
One of the most important things you can do with .htaccess is blacklist IP addresses. You can do so with the following code:
1.<Limit GET POST PUT>2. order allow,deny3. allow from all4. deny from 123.456.7895.</LIMIT>Source – Perishable Press
C – WP-Config Protection
Your wp-config file contains your database name, your database username and your database password. In other words, youâll want to keep it secure.
1.# protect wpconfig.php</code>2.<files wp-config.php>3.order allow,deny4.deny from all5.</files>Source – Josiah Cole
D – Disable Directory Browsing
1.<em># disable directory browsing</em>2.<em>Options All -Indexes</em>
Source- Josiah Cole
E – Explanation
I bet if I asked you to explain exactly what .htaccess is, youâd struggle to tell me exactly. To be honest, until I wrote this, I wasnât totally sure. Wikipedia explains in a nice, jargon free way:
.htaccess (hypertext access) is the default name of directory-level configuration files that allow for decentralized management of configuration when placed inside the web tree.
The Wikipedia article then goes on, with some examples of common usage:
- Authorization, authentication
- .htaccess files are often used to specify the security restrictions for the particular directory, hence the filename âaccess.â The .htaccess file is often accompanied by a .htpasswd file which stores valid usernames and their passwords. [3]
- Customized error responses
- Changing the page that is shown when a server-side error occurs, for example HTTP 404 Not Found
- Rewriting URLs
- Servers often use .htaccess to rewrite long, overly comprehensive URLs to shorter and more memorable ones.
- Cache Control
- .htaccess files allow a server to control User agent caching used by web browsers to reduce bandwidth usage, server load, and perceived lag.
F – Feedburner
Feedburner is a bloggerâs best friend. Trouble is, directing your feed to it is a bit of a pain. The solution: a .htaccess hack of course!
1.# temp redirect WordPress content feeds to feedburner2.<IfModule mod_rewrite.c>3. RewriteEngine on4. RewriteCond %{HTTP_USER_AGENT} !FeedBurner   [NC]5. RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]6. RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/perishablepress [R=302,NC,L]7.</IfModule>Source – Perishable Press
G – Get an RSS Feed on a static page
This is quite complicated, so check out the source below. In a nutshell it is a way of getting round using Javascript (because it doesnât do the SEO any good).
Source – adityaspeaks.com
H – Disable hotlinking
Hotlinking. According to Wikipedia, also known as âleeching, piggy-backing, direct linking, offsite image grabs and bandwidth theftâ. In other words it is using an image from another site. If people do it to you, itâll use up your bandwith. You can stop it with the .htaccess hack below.
1.#disable hotlinking of images with forbidden or custom image option2.RewriteEngine on3.RewriteCond %{HTTP_REFERER} !^$4.RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC]5.#RewriteRule \.(gif|jpg)$ - [F]6.RewriteRule \.(gif|jpg)$ http://www.yourdomain.com/stealingisbad.gif [R,L]
Source – Josiah Cole
I – Important!
Yeah, ok, I got a bit desperate trying to find something that begins with âIâ
. But, that doesnât mean this isnât useful; itâs very important!
Backup. Always, always make sure you have a backup to hand; the slightest mistake will be fatal.
J – Jauntily show the adminâs email address in error message
If something goes wrong it is always helpful for visitors to have an email they can contact. You can display
K – Keep RSS âcontent thievesâ away
It isnât nice when people steal your content. One of the ways âcontent thievesâ scrape content from sites is by simply using your RSS feed. If youâve got the scraperâs IP address (which is very easy to do; Google it) then you can use your .htaccess file to block the scraper. The code below redirects a site taking your feed back to another feed (ie their feed). Replace the IP on line two with the offending siteâs and the feed on line three with the offending siteâs feed.
1.RewriteEngine on2. RewriteCond %{REMOTE_ADDR} ^69.16.226.123. RewriteRule ^(.*)$ http://newfeedurl.com/feedSource – Seo Black Hat
L – Limiting number of simultaneous connections
To limit the number of simultaneous connections to a directory or your entire site, use the below line. If you place it in a directory other than the root directory, then it will limit the connections to that directory and its sub-directories only. Placing it in htaccess file of root directory will implement it for entire site.
1.MaxClients < number-of-connections>Source – Pix.l|ne
S -Â Stop spam!
You block spammers, everyone or just yourself using the code below. See âNâ for another spam-stopping technique.
1.Order allow,deny2. Deny from < incoming -address >3. Allow from < incoming -address>Source – pix.l|ne
M – Maintenance
It doesnât matter what the reason is, at some point in your life youâll probably want to make maintenance page. Replace â/maintenance.htmlâ with whatever the url of your maintenance page is and put your own IP address on line three.
1.RewriteEngine on2.RewriteCond %{REQUEST_URI} !/maintenance.html$3.RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.1234.RewriteRule $ /maintenance.html [R=302,L]Source – CatsWhoCode/Woueb.net
N – Deny no referer requests [stop spam comments!]
Slightly simpler than the spam-stopping solution under âSâ, what this hack does is utilise the fact that most spammes use bots coming from ânowhereâ. The hack checks to see where a comment is coming from, and if it is coming from ânowhereâ then it blocks it. Simple.
1.RewriteEngine On2.RewriteCond %{REQUEST_METHOD} POST3.RewriteCond %{REQUEST_URI} .wp-comments-post\.php*4.RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]5.RewriteCond %{HTTP_USER_AGENT} ^$6.RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]Source – WPRecipes
O – Force files when opening to âsave asâ
If youâre offering files for download then the hack below will be very useful – it forces files to save as instead of opening or streaming.
1.AddType</span> application/octet-stream .avi .mpg .mov .pdf .xls .mp4Source – AskApache
P – Protect your .htaccess file.
After youâve spent all that time protecting your blog from .htaccess attack, the last thing you want to do is leave your .htaccess file itself open to attack!The hack below prevents external access to any file with .hta (or any case insensitive variation). Place the code below in your domainâs root .htaccess file.
1.# STRONG HTACCESS PROTECTION</code>2.<Files ~ "^.*\.([Hh][Tt][Aa])">3.order allow,deny4.deny from all5.satisfy all6.</Files>Source: Perishable Press
Q – Quicken your siteâs loading time by caching
If youâre paying for what bandwith you use, this article can save you cash!
Source – Samaxes
R – Redirect to other pages on your site
1.RedirectMatch 301 ^/blog/.*$ http://domain.tld/target.htmlSource – Perishable Press
S - Spam!
.htaccess is great for stopping comment spam, and Jeff over at Perishable Press has put together a huge blacklist you can copy and paste that should stop you getting so much spam! Link.
T – Set the timezone of the server
The hack below lets you set the timezone of the server:
1.SetEnv</span> TZ America/IndianapolisSource – AskApache
U – Remove /category/ from your category URL
Having /category/ in a category URL seems a bit useless. How do I get rid of it, I hear you cry! A .htaccess hack, of course!
1.RedirectMatch 301 ^/category/(.+)$ http://www.askapache.com/$12.# OR3.RewriteRule ^category/(.+)$ http://www.askapache.com/$1 [R=301,L]Source: AskApache
V – Valiantly automatically fix URL spelling mistakes
Yep. I got desperate. Well what .htaccess trick can you think of that starts with âvâ?
This neat trick will auto-correct simple URL spelling mistakes
1.<IfModule mod_speling.c>2. CheckSpelling On3. </IfModule>Source – Vortex Mind
W – Redirect from http://www.whatever to http://whatever
Using a 301 (permanent) redirect, you can move all visitors to http://www.yoursite to http://yoursite
1.# permanently redirect from www domain to non-www domain2.RewriteEngine on3.Options +FollowSymLinks4.RewriteCond %{HTTP_HOST} ^www\.domain\.tld$ [NC]5.RewriteRule ^(.*)$ http://domain.tld/$1 [R=301,L]Source: Stupid htaccess tricks
X – Make your wp-login.php page xenophobic
Xenophobic: âan intense fear or dislike of forigners or strangersâ
I think it is quite appropriate to call your wp-login page xenophobic if you install this hack; it wonât let anyone access it apart from yourself!
1.<Files wp-login.php>2. Order deny,allow3. Deny from All4. Allow from 123.456.789.05. </Files>Source – Reaper-X
Y – Easily rename your .htaccess file
What do you do if your server doesnât like the .htaccess file format? Rename the .htaccess file! You can rename it to whatever you like, using the code below:
1.# rename htaccess files</code>2. <code>AccessFileName ht.accessSource – Perishable Press
Z – Say zygote in your .htaccess file
So you want to be able to put the word âzygoteâ in your .htaccess file? Youâll be needing to make a comment. Comments are really easy to do, just use # at the beginning of a line, which tells the server to ignore the line.
1.# see - this is a comment - you can only use letters and numbers and - and _ That is why there are no commas
