Kegunaan File .htaccess


If you manage and edit your own website or run a blog with it’s own domain then you are probably aware of a type of file called the .htaccess file. You may or may not know what this file actually does, or how to create and edit one but fret not, I’m here to help.

This quick tutorial will provide you with an htaccess file that does the following:

1. Protects itself (security)
2. Turns the digital signature off (security)
3. Limits upload size (security)
4. Protects wp-config.php (security)
5. Gives access permission to all visitors with exceptions (security, usability)
6. Specifies custom error documents (usability)
7. Disables directory browsing (security)
8. Redirect old pages to new (optional)
9. Disables image hotlinking (bandwidth)
10. Enables PHP compression (bandwidth)
11. Sets the canonical or “standard” url for your site (seo, usability)

1. Step 1, create a blank .htaccess file. This can be done in Notepad or a comparable simple text editor of your choice (no MS Word does not count although it’s possible). Open Notepad and Click Save, name this file htaccess.txt. If you’re using Windows XP the OS won’t allow you to name a file e .htaccess but don’t worry, you can rename it once it’s been uploaded to your server (no idea how Linux, Vista or OSX handle this).

2. Add content to htaccess.txt. Now that you have htaccess.txt saved, you can start to edit the file and use it to better manage your site without relying on complex PHP or bloated JavaScript code.

The example htaccess file below is one that can be used for a website like this one (running WordPress and nothing else), simply un-comment the sections you’d like to use by removing the # at the beginning of the line and copy+paste the contents into your own .htaccess file.


# protect the htaccess file
<files .htaccess>
order allow,deny
deny from all

# disable the server signature
ServerSignature Off

# limit file uploads to 10mb
LimitRequestBody 10240000

# protect wpconfig.php
<files wp-config.php>
order allow,deny
deny from all

#who has access who doesnt
order allow,deny
#deny from
allow from all

#custom error docs
ErrorDocument 404 /notfound.php
ErrorDocument 403 /forbidden.php
ErrorDocument 500 /error.php

# disable directory browsing
Options All -Indexes

#redirect old to new
Redirect 301 /old.php

#block referring domains
RewriteEngine on
RewriteCond %{HTTP_REFERER} [NC]
RewriteRule .* – [F]

#disable hotlinking of images with forbidden or custom image option
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www.)?*$ [NC]
#RewriteRule .(gif|jpg)$ – [F]
#RewriteRule .(gif|jpg)$ [R,L]

# php compression – use with caution
<ifmodule mod_php4.c>
php_value zlib.output_compression 16386

# set the canonical url
RewriteEngine On
RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

# protect from spam comments
RewriteEngine On
RewriteCond %{REQUEST_URI} .wp-comments-post.php*
RewriteCond %{HTTP_REFERER} !.** [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]


3. Upload htaccess.txt. Once you’ve created your master piece of an .htaccess file upload the htaccess.txt file to your web server via ftp (in ASCII mode) and rename the file to .htaccess. Once it’s been renamed change the file permissions of the .htaccess file to 644 to further protect it from malicious hacker types.


4. Test, Test, Test. Go to your site, is it still up? Good, now check to see if you can access files you protected, or try and see a directory listing. Not all variables are testable but do your best to make sure your file is working.

Lastly Josiah Cole dot com is now running a variation of the htaccess file above with no hotlink protection (I only host a couple images) and no redirects or custom errors docs (yet). No problems *yet* but I’m still running tests to make sure there are no problems. Maybe my visitors can help me do this by commenting? If I like it I’ll add your suggestion to the article and give you some URL lovin’.

Note: If you are already using a custom permalink structure to format page names, you’ll need to keep that code in the htaccess file in order for that to continue functioning. To see your htaccess file in WordPress click Manage>Files>.htaccess (for rewrite rules).


Go for what you want to be!!! No matter what they say . ejekan serta hinaan TIDAKAKAN MEMBANTU siapa-siapa

10 Responses

  1. Chung ManningsJuly 15, 2012 at 6:37 pmReply

    I like this website very much, Its a really nice berth to read and incur information. “Do not trust your memory it is a net full of holes the most beautiful prizes slip through it.” by Georges Duhamel.

  2. Ronnie BridgefordAugust 17, 2012 at 1:48 amReply

    I together with my friends have already been analyzing the nice secrets and techniques on your website and so suddenly I had a horrible suspicion I had not expressed respect to the website owner for those techniques. The young men happened to be stimulated to learn them and now have truly been taking advantage of them. I appreciate you for turning out to be so helpful and then for making a choice on certain incredibly good issues millions of individuals are really desirous to be informed on. My personal sincere regret for not saying thanks to sooner.

  3. Jasa SEOAugust 25, 2012 at 8:59 amReply

    Wow, marvelous weblog layout! How lengthy have you ever been running a blog for? you made running a blog look easy. The overall glance of your web site is magnificent, let alone the content!

  4. infrared space heaterAugust 26, 2012 at 1:46 amReply

    Hi there this is kinda of off topic but I was wondering if blogs use WYSIWYG editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding skills so I wanted to get advice from someone with experience. Any help would be greatly appreciated!

  5. lvoutleten.comSeptember 29, 2012 at 4:47 pmReply

    Fantastic post, thank you so much for sharing. Do you happen to have an RSS feed I can subscribe to?

  6. nordstrom toms shoesOctober 23, 2012 at 7:52 amReply

    I’ve identified your post very informative and fascinating. I appreciate your points of view and I agree with so numerous. You’re done a fantastic job with generating this clear enough for anyone to recognize.
    nordstrom toms shoes

  7. Gabrielle MadesNovember 1, 2012 at 3:37 amReply

    Normally I do not learn article on blogs, however I would like to say that this write-up very forced me to take a look at and do so! Your writing taste has been surprised me. Thank you, very great post.

  8. Xelerated GuidesNovember 1, 2012 at 7:35 pmReply

    I really appreciate this post. I’ve been looking all over for this! Thank goodness I found it on Bing. You’ve made my day! Thanks again!

  9. zygor guideNovember 7, 2012 at 7:59 amReply

    It is truly a nice and useful piece of information. I¡¦m glad that you shared this useful info with us. Please stay us up to date like this. Thank you for sharing.

  10. aJune 21, 2014 at 2:34 amReply

    whoah this weblog is great i love studying
    your posts. Stay up the great work! You recognize, a lot of
    people are hunting around for this information,
    you can help them greatly.

Leave a Reply