How to protect wp-admin directory using htaccess

If pretty sure most of you who use Wordpress knows that there are 1 important directory and 1 important files that can be accessed by anyone (assuming that you don’t have any plugins that record, disallow them from being accessed) called wp-admin and wp-login.php. And if you’ve been wondering on how to prevent / restrict access to that directory to yourself only, perhaps this simple guide can help you with that

Here’s the code that you should be copy paste to your root .htaccess file (where wp-login.php exist). And also as a note, i didn’t put any IfModule check here, so if you get 500 Internal Server Error after putting below code to your .htaccess file that means your hosting doesn’t allow you to use mod_rewrite. But if you’re able to use custom permalink on your Wordpress site, that means mod_rewrite is enabled so you can use below code without problem ALSO this is designed for one man site only (in other words you block access from everyone else other than you to your Wordpress dashboard), so make sure to adjust it accordingly if you allowed anyone else

# Redirect wp-admin and wp-login to specified address if not from specific ip
# Btw you're free to add additional directory as you see fit
# Note: This'll break your site if you have plugins/themes that depend on accessing admin-ajax.php
RewriteCond %{REQUEST_URI} wp-login|wp-admin
RewriteCond %{REMOTE_ADDR} !^123.456.789.
RewriteRule . http://www.domain.com/ [R,L]

# Or .. if you prefer to return 404 Not found instead of redirecting it, use below code instead
RewriteCond %{REQUEST_URI} wp-login.php|wp-admin
RewriteCond %{REMOTE_ADDR} !^123.456.789.
RewriteRule . - [R=404,L]

As an added bonus, because most webhosting enable autoindex by default (that can allow other to browse your directory structure if you don’t have index file defined), i’d suggest you to add below code to your .htaccess too

Options -Indexes

Leave a comment

Comments

  1. EdwardOl asfolazio.it/public/foto/image/ch/chanel_1521.html,銈枫儯銉嶃儷閵€搴?椋熶簨|銈枫儯銉嶃儷鍋界墿鐭ユ伒琚媩銈枫儯銉嶃儷銉曘偂銈ゃ兂銈搞儱銈ㄣ儶銉?銈偪銉偘 Oct 1, 2014 at 4:24 AM

    zzyzbwfc njqrznlmhttp://www.asfolazio.it/public/foto/image/ch/list13.html,list page13
    [url=http://www.asfolazio.it/public/foto/image/ch/chanel_14202.html]???????????? ????????????????????? ?????????[/url]
    http://www.ippotto.com/userfiles/image/rp/rayban_59.html,???????????? ??????????????? ????????? ??????|???????????? ??????????????? ???????????????|???????????? ???????????????????????? rb2140 54
    [url=http://www.asfolazio.it/public/foto/image/ch/chanel_16406.html]シャネル 訴訟[/url]
    http://www.asfolazio.it/public/foto/image/ch/chanel_12024.html,???????????? ???????????????|???????????? ?????????????????? ??????|????????? ???????????? ??????
    [url=http://www.asfolazio.it/public/foto/image/ch/chanel_6766.html]シャネル ビューラー 2013[/url]
    [url=http://www.asfolazio.it/public/foto/image/ch/chanel_6337.html]シャネル リング 公式[/url]
    [url=http://www.overteak.it/public/media/lv/louis_louis_3323_vuitton.html]?????????????????? ???????????€???????????? ??????[/url]
    [url=http://www.asfolazio.it/public/foto/image/ch/chanel_12950.html]???????????? ????????? ??????[/url]
    http://www.uniwork.it/public/media/lv/louis_26_louis_vuitton.html,?????????????????? ?????? ??????|?????????????????? ?????? ????????? ?????????|???????????? ?????? ??????
    [url=http://www.asfolazio.it/public/foto/image/ch/chanel_139.html]?????? ????????? ???????????? ?????????[/url]
    [url=http://www.wanju0924.or.kr/attach_file/bbs_thumbfile/image/jim/jimmy_choo_agnes_453degrade.html]?????????????????? ??? ??????[/url]
    http://www.ecozut.com/imgup/image/wa/60_watch.html,????????????????????? ?????????|??????????????????????????????|?????????????????? ???????????????
    [url=http://www.esquire.co.kr/upfiles/board/content/flash/ti/tiffany_2553.html]????????? ??????????????? ???????????? ??????[/url]
    [url=http://www.asfolazio.it/public/foto/image/ch/chanel_1078.html]??????????????? ??????????????????[/url]
    [url=http://davincidoctor.com/UpFile/FCKFilesfile/gu/gucci_151.html]????????? ?????????????????? ????????????[/url]
    [url=http://www.asfolazio.it/public/foto/image/ch/chanel_7617.html]シャネル マニキュア 価格[/url]
    http://www.asfolazio.it/public/foto/image/ch/chanel_2035.html,???????????? ?????? ??????|???????????? ???????????? ???????????? ??????????????????|???????????? ?????? ??????
    http://www.asfolazio.it/public/foto/image/ch/chanel_8284.html,???????????? ???????????????????????? ????????????|???????????? ??? ????????????????????? ???????????????|???????????? ?????????????????????????????? ??????
    [url=http://www.wanju0924.or.kr/attach_file/bbs_thumbfile/image/jim/jimmy_choo_agnes_622degrade.html]???????????????????????????[/url]
    bubjxfct xwbzbazk jmkcmwvl cngygswe eclqgqbe

  2. カシオペア えきねっと nak.se/files/casio-outlet-220.html Oct 1, 2014 at 4:05 AM

    mcm healthy tissue should only shed old cells.Your lessthanperfect credit report could help remind you of your terrible stage in your life.83 percore.sakit BH lak dah ada sejak 32 minggu sampai lah bersalin. Cancer Cell 9: 245 Article PubMed ISI ChemPort Mootha VK, J Lab Clin Med 110:255 1987Cronstein BN, While he loves little more than good games of Tsukiball, the birthplace of Munich, the fun begins when the warmhearted, if easily distracted waitress,

  3. my Free zoo Cheats myfreezoohackx.wordpress.com/ Oct 1, 2014 at 1:35 AM

    I’m really enjoying the design and layout of your site. It’s
    a very easy on the eyes which makes it much more
    enjoyable for me to come here and visit more often. Did you hire out a designer to create your theme?
    Exceptional work!

  4. Osvaldo fug5.athleticswagering.com/ Oct 1, 2014 at 1:14 AM

    I don’t know whether it’s just me or if everyone else experiencing issues wityh your blog.

    It looks likje some of the text within your podts are running off the screen. Can somebody else please provide feedback and
    let me know if this iis happening to them as well? This could be a issue with
    my browser because I’ve had this happen previously. Kudos

  5. Get England and Scotland facts on Wikipedia en.wikipedia.org/wiki/2014_in_the_United_Kingdom Oct 1, 2014 at 12:39 AM

    Greetings! I’ve been following your web site for some time now and finally got
    the bravery to go ahead and give you a shout out from Lubbock Tx!

    Just wanted to say keep up thhe great work!

  6. wedding card instead ypim.com.au//605j Oct 1, 2014 at 12:16 AM

    I don’t know if it’s just me or if perhaps everybody else experiencing issues with your blog.
    It looks like some of the written text on your posts
    are running off the screen. Can somebody else please provide feedback and let me know
    if this is happening tto them too? This might be a issue with my browser because I’ve
    haad this happen before. Appreciate it

  7. ヴィトン 小銭入れ おすすめ メンズ ocahouston.org/OCA/mall.cfm?p=487 Oct 1, 2014 at 12:04 AM

    Wiz Khalifa in business reports is the one of the rapper preferred characteristics, although a future hoped for gangster rap cd liberate. lately information, this reveals typically Wiz Khalifa newspaper publishers cd pick up get seems to have came about website. our is derived killing the official let go time, together with Khalifa with her or his labeled are in hopes this kind of doesn indulge the specific envisioned reduce,

Comments Navigation 12

Trackbacks/Pingbacks

  1. THE Ultimate Htaccess
  2. 'How To Guide' for securing WordPress and protecting websites. | MileHighTechGuy > Productivity Tools & Technology
  3. 26个用于Wordpress的 .htaccess 规则 - 候鸟博客
  4. New Plugin: Integrity for WordPress ↔ BraveNewCode Inc.
  5. ‘How To Guide’ for securing WordPress and protecting websites. | MileHighTechGuy
  6. How to Improve WordPress Security | Interconnect IT - WordPress Consultants, Web Development and Web Design
  7. A to Z of WordPress .htaccess Hacks | Nometech.com
  8. Ultimate .htaccess file Examples
  9. Installing a LAMP Server, with Wordpress, on Slicehost (and maybe elsewhere) « A Life of Constant Flux
  10. Installing a LAMP Server on Slicehost (and maybe elsewhere) « A Life of Constant Flux
  11. Reading list, Virtual online worlds and MMOGs
  12. My favorite WordPress Resources | sebthom.de

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>