• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
logo

All Blogging Tips

Everything About Blogging

  • Home
  • Start a Blog
  • About
  • Contact
  • Work With Me
  • Tools I Use

Top .htaccess Tips to Secure Your WordPress Site

By Ammar Ali 6 Comments

htaccess

Since website security has become a common concern, webmasters exercise great care when maintaining their sites. In addition to some frequently-used methods, like WordPress security plugin installation, password enhancement and the use of SSL, you can take .htaccess into consideration. This is a great method recommend by many experts and web resources sites like PHPMatters

Maybe now, you have been pulled in a fog and thirst after the reason why .htaccess can make a big difference on website security improvement and what you can do with it. Here, we are going to clear all your doubts by showing details on how to secure your WordPress website using .htaccess.

Table of Contents
  • What Is .htaccess?

What Is .htaccess?

.htaccess, short for hypertext access, is a configuration file used to store server directives and allows decentralized management on a web server. With the help of this file, you are able to enable or disable directives over the whole site, like rewriting URLs, blocking users, controlling cache, and protecting password, etc. As thus, by overriding some security-related settings, you can safeguard your site effectively.

If .htaccess is not available on your site, you are required to open a new text and include configuration commands required. Then save the .txt file and upload it to your site. Once getting through it, you need to rename the file as .htaccess and upload it using FTP.

Protect .htaccess Itself

If the .htaccess file suffers attacks, other protected files are not immune. Thus, you should attach great importance to the security of your .htaccess file by using the code as below.

<Files .htaccess>

order allow,deny

deny from all

satisfy all

</Files>

When people get to intrude the .htaccess file, there is a 403 forbidden error opening on their view.

Disable Hotlinking with .htaccess

You may encounter a situation that your peer blogger embezzles your images, and displays these images using your original URL. When visitors load these images on his site, the usage of bandwidth is from your website. This is called as hotlinking.

To prevent your bandwidth from being stolen by other webmasters, you should enable hotlink protection using .htaccess. To do this, you can include the following content in the .htaccess file.

RewriteEngine on

RewriteCond %{HTTP_REFERER} !^$

RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?YourDomain [NC]

RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]

Protect wp-config.php with .htaccess

As a WordPress file of great concern, wp-config.php gets hold of all critical information about database, including username, password, host and database name. The information is used to enable data store and retrieve. Thus, you have to take this file seriously, or your site will be in danger. The following lines tell how to strengthen wp-config.php with .htaccess.

<Files wp-config.php>

order allow,deny

deny from all

</Files>

Stop Directory Browsing with .htaccess

A directory browsing enabled website allows web browsers to display the content of all your directories when they cannot search the file of index.php or index.html. However, some of these directories may include the confidential files or folders that are important to your website. If web browser makes those details public, your website is more likely to be attacked by hackers, because they have known your secret very well.

In this case, you’d better take some measures to stop directory browsing. The use of .htaccess is a great method to this end when including the following commands. Unlike Godaddy, some companies do this by default.

# directory browsing

Options All -Indexes

Restrict Access to Admin Area

The admin area is a private place of your website, which enables full access for you to handle administrative functions. However, there are also some other admin roles available like editor, author, subscriber and author having partial access. To prevent these additional roles from releasing your valuable information, you’d better take full control of the admin area instead of sharing a portion to others.

To do this, you can add the following code to the .htaccess file and fill your IP address in the designated section.

order deny,allow

allow from {your IP Address}

deny from all

Stop Unwanted Visitors Accessing to Your Site

When suffering some vicious visitors making a threat to your website, you should take action to stop them coming again. Frankly, .htaccess makes it easy to clear up all threats to the website only if you use following snippet.

<Limit GET POST>

order allow,deny

deny from {IP Address of the Denied Visitor}

allow from all

</Limit>

Note that, the mentioned code can only ban one person at a time. If you want to increase the banning number, you can edit the code as below to add the banned users as you want.

<Limit GET POST>

order allow,deny

deny from {IP Address of the Denied Visitor1}

deny from {IP Address of the Denied Visitor2}

allow from all

</Limit>

To be frank, blocking the bad users is just a stalling tactic, for which people can come again after converting the IP address into a new one. Thus, you have to make the safeguarding operation consistent and look for long-term effective methods.

Did I missed any tip? How are you securing your WordPress blog?

Share this post:

Share on X (Twitter) Share on Facebook Share on Pinterest Share on Email Share on WhatsApp

About Ammar Ali

A blogger, web designer, front-end developer and WordPress specialist since 2011. I started this blog during high school. Here I share what I've learned so far and what I continue to learn through blogging so that I can be of assistance in some way to improve your blog. Read more here.

Reader Interactions

Comments

  1. Santiago Bore says

    January 29, 2015 at 4:00 pm

    These tips are useful, but everyone should edit the .htaccess file carefully. Or it can affect your website adversely.
    An alternative way may be using iThemes security as I think most of this can be done using that plugin. It’s free too.

    Reply
  2. Amit Kumar says

    January 27, 2015 at 1:43 am

    Hi Ammar,

    This is really a so much profitable tutorial for me. All these .htaccess Tips for Securing my WordPress Site has solved my problem and i got the perfect solution from here. Thank you so much for sharing :)

    Reply
  3. MLM says

    December 13, 2014 at 9:03 am

    Security has become an important issue lately for me.

    As far as I know a wp site/blog can get some fixes in htaccess to make it stronger. Your top htaccess tips are pretty usefull… which one is the very best of them? I won´t know ´till watch ´em working right?

    Reply
  4. Fakharuddin says

    December 10, 2014 at 8:57 pm

    Hi Ammar,

    .htaccess is most important part of WP site that helps to keep WP site safe and secure from hacking attempts, various, malware, robots etc. We should configure it perfectly.

    You mention here some great way to configure .htaccess file easily and perfectly.

    Thanks for the great sharing.

    Reply
  5. Jeff M says

    December 9, 2014 at 7:13 pm

    This a a great piece about .htaccess. I really agree with you when you say this. More people need to read this. Thanks again.

    Reply
  6. Ryan Biddulph says

    December 5, 2014 at 4:58 am

    Hi Ammar,

    Way cool tutorial! I think I added htaccess manually, or, my developer did. I’ve no clue in hell now that I think about it, lol! I did it with my old blog and think that I did it with my new blog. Maybe I should get serious about finding this out ;)

    Thanks Ammar for the share!

    Ryan

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Get Blogging & SEO Tips by Email

Get helpful blogging, SEO, and content tips delivered straight to your inbox. No spam.

Join 3,489 other subscribers

Popular Posts

  • Is Your Blog Properly Optimized for Performance and SEO?
  • 10 Powerful Ways to Become a Famous Blogger
  • Google AdSense vs Affiliate Marketing: A Simple Comparison for Beginners
  • Effective Ways to Increase Content Reach and Audience Engagement
  • 12 Things to Do Before Applying for Google AdSense
  • Are Backlinks Becoming Less Valuable in Modern SEO?
  • Step-by-Step Guide to Creating a Successful Travel Blog
  • How to Start as a Freelance Writer & Is It Worth?
  • Add Smooth Multi Level Drop-Down Menu In Blogger
  • How To Delete A Blogger Blog Permanently In 5 Minutes (+ FAQs)

Let Me Help You!

Let me take care of your website and make it run like a champ. I can help you with blog setup, migration, quick fixes or maintenance services.

Work With Me

Footer

About This Site

All Blogging Tips helps beginners learn how to start, grow, and monetize blogs using WordPress. I share practical guides and honest recommendations based on real blogging experience.

Read more →

Site & Resources

  • Tools I Use
  • About
  • Advertise Here
  • Contact
  • Disclosure Policy
  • Copyright Policy
  • Privacy Policy

Start & Grow Your Blog

  • A Ridiculously Helpful Guide to Start Your Own Blog In 10 Minutes
  • How To Grow Your Blog And Build An Audience
  • How To Make Money From Your Blog
  • Cheap WordPress Hosting
  • Free WordPress Hosting

Copyright © 2026 All Blogging Tips · Powered by InMotion Hosting · WordPress · Log in