ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Internet & the Web»
  • Web Page & Web Site Development

WordPress htaccess Security

Updated on February 24, 2016

When it comes to creating a WordPress blog or website there are steps that you should take to help ensure that your WordPress site is secure. One of the easiest ways to do this is to create an htaccess file that is optimized to increase overall site security

The htaccess file of your WordPress site can be created by simply creating a text file and saving it as .htaccess

Ensure that when you create this file, you don't forget to use the period character before the h otherwise the file is useless for it's purpose. Once the file has been created, upload it to the root directory of your WordPress installation by using either the control panel area in your hosting account or by FTP. When you upload the file, the following code should automatically be added to the file.

# 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]

</IfModule>

# END WordPress

To ensure this code was added, please open the .htaccess file with a text editor and view it. If the code was not added automatically, chances are the file is not writable. To fix this you must change the permissions of the file. WordPress Org recommends setting permissions to 644.

If the code isn't added after you change the permissions you may have to manually add it yourself. Please be careful when editing this file. One missed line of code or any extra characters added to the code could cause your site to go down. If this happens, just delete the file completely and start over.

After your WordPress .htaccess file is created, uploaded and confirmed that it's editable and showing the above lines of code, you can being optimizing the file by adding additonal code that controls various security functions of your WordPress site.

Because HTACCESS files have so much control over your site its important to protect the file itself. The following code will prevent someone from accessing it other than you.

<files ~ "^.*\.([Hh][Tt][Aa])">

order allow,deny

deny from all

satisfy all

</files>

The second file that you should keep secure is your wp-config file which has sensitive information in it such as usernames and passwords. To do this add the following code to the .htacces file

<files wp-config.php>

order allow,deny

deny from all

</files>

There are some files that should never be accessed such as those in the wp-includes directory. Block those files with this code:

# Block the include-only files.

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^wp-admin/includes/ - [F,L]

RewriteRule !^wp-includes/ - [S=3]

RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]

RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]

RewriteRule ^wp-includes/theme-compat/ - [F,L]

</IfModule>

To prevent outsiders from browsing any of your directories then use this line of code:

# disable directory browsing

Options All -Indexes

The full completed line of code should resemble this:

# 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]

</IfModule>

# END WordPress

<files ~ "^.*\.([Hh][Tt][Aa])">

order allow,deny

deny from all

satisfy all

</files>

<files wp-config.php>

order allow,deny

deny from all

</files>

# Block the include-only files.

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteRule ^wp-admin/includes/ - [F,L]

RewriteRule !^wp-includes/ - [S=3]

RewriteRule ^wp-includes/[^/]+\.php$ - [F,L]

RewriteRule ^wp-includes/js/tinymce/langs/.+\.php - [F,L]

RewriteRule ^wp-includes/theme-compat/ - [F,L]

</IfModule>

# disable directory browsing

Options All -Indexes

Creating this simple yet effective file can help dramitcally increase the security of your site by restricting people other than yourself from accessing imporant files on your WordPress install.

Comments

    0 of 8192 characters used
    Post Comment

    • calvinaustins profile image

      Calvin 18 months ago from UK

      Indeed sharing. Thanks for the code which can be really helpful to me and others.

      Keep sharing..

      Cheers!!