Title: Code for .htaccess
Last modified: December 1, 2021

---

# Code for .htaccess

 *  Resolved [Robert Eichhorn](https://wordpress.org/support/users/robert-eichhorn/)
 * (@robert-eichhorn)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/code-for-htaccess/)
 * I want to add some code to my .htaccess file to prevent hackers from accessing
   my wp-includes folder. I found 2 different examples of code to add. One example
   starts the code with <IfModule mod_rewrite.c>. The other example starts the code
   with RewriteEngine On. I would like to know the reason for the 2 different setups
   and what one should I use. Here are the 2 different examples:
 * Example 1:
    <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # more code
   goes here </IfModule>
 * Example 2:
    RewriteEngine On RewriteBase / # more code goes here RewriteRule 
   ^wp-includes/theme-compat/ – [F,L]

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [barnez](https://wordpress.org/support/users/pidengmor/)
 * (@pidengmor)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/code-for-htaccess/#post-15120312)
 * Example 2 needs to be nested within opening (`<IfModule mod_rewrite.c>`) and 
   closing
    (`</IfModule>`) mod_rewrite rules. These could wrap this individual 
   set of directives (as seen in example 1), or a group of directives that require
   mod_rewrite in the `.htaccess` file.
 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/code-for-htaccess/#post-15122199)
 * Enclosing rewrite blocks with `<IfModule mod_rewrite.c>...</IfModule>` is an 
   artifact of a long-gone era when servers had very little memory, and Apache would
   be configured to conserve as much memory as possible. If Apache/Litespeed was(
   correctly) built in the past 10 or so years, mod_rewrite will be loaded and the
   enclosure is unnecessary.
 * This is one of many legacy items in WordPress that should probably be removed.
   Use of the PHP `mysql` extension in wp-db.php is another example.
 *  Thread Starter [Robert Eichhorn](https://wordpress.org/support/users/robert-eichhorn/)
 * (@robert-eichhorn)
 * [4 years, 5 months ago](https://wordpress.org/support/topic/code-for-htaccess/#post-15141836)
 * Barnez and Dion – thanks for your help. I will ask the Apache community for their
   input on the issue.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Code for .htaccess’ is closed to new replies.

## Tags

 * [htaccess](https://wordpress.org/support/topic-tag/htaccess/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [Robert Eichhorn](https://wordpress.org/support/users/robert-eichhorn/)
 * Last activity: [4 years, 5 months ago](https://wordpress.org/support/topic/code-for-htaccess/#post-15141836)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
