# Modifying EDD .htaccess file rules

Easy Digital Downloads uses a .htaccess file (for Apache servers) to protect product download files. This file is placed in *wp-content/uploads/edd/*. The rules in the file will differ depending on your *Download Method* set in *Downloads → Settings → Misc*.

If Download Method is set to Forced, the default .htaccess rules are:

```
Options -Indexes
deny from all

 &lt;filesmatch &#039;.(jpg|png|gif|mp3|ogg) &lt; pre&gt;
  &lt;p&gt; If Download Method is set to Redirect, the rules are:&lt;/p&gt;

  Options -Indexes
```

### How to modify .htacess rules

Below are different options on modifying the .htaccess rules, either via a filter or using a WordPress plugin.

**Note:** EDD rewrites the .htaccess once a day so you cannot make changes directly to the .htaccess file itself, otherwise those changes will get overwritten.

#### 1. Update rules using a the *edd\_protected\_directory\_htaccess\_rules* filter:

These rules can be changed using the *edd\_protected\_directory\_htaccess\_rules* filter. For example, if you want to block direct access to .mp3 files (by default they are allowed), you can use this:

```
&lt;?php
function edd_custom_modify_htaccess_rules( $rules, $method ) {
	switch( $method ) :
		case &#039;redirect&#039; :
			// Prevent directory browsing
			$rules = &quot;Options -Indexes&quot;;
			break;
		case &#039;direct&#039; :
		default :
			// Prevent directory browsing and direct access to all files, except images (they must be allowed for featured images / thumbnails)
			$rules = &quot;Options -Indexes\n&quot;;
			$rules .= &quot;deny from all\n&quot;;
			$rules .= &quot;&lt;FilesMatch &#039;\.(jpg|png|gif|ogg)$&#039;&gt;\n&quot;;
			    $rules .= &quot;Order Allow,Deny\n&quot;;
			    $rules .= &quot;Allow from all\n&quot;;
			$rules .= &quot;&lt;/FilesMatch&gt;\n&quot;;
			break;

	endswitch;

	return $rules;
}
add_filter( &#039;edd_protected_directory_htaccess_rules&#039;, &#039;edd_custom_modify_htaccess_rules&#039;, 10, 2 );
```

In order for the changes to take effect, you can wait 24 hours or, go to ***Downloads &gt; Settings &gt; Misc***, change the **Download Method** to a different value and click “**Save Changes**”. This will force the .htaccess file to be updated. Make sure to change the **Download Method** back to the previous value and hit **Save Changes** again.

### Emptying .htaccess

If you need to get rid of everything, including

```
Options -Indexes
```

then you can use a function similar to above, but with nothing in it. Example:

```
&lt;?php
function edd_custom_modify_htaccess_rules( $rules, $method ) {
	$rules = &quot;&quot;;

	return $rules;
}
add_filter( &#039;edd_protected_directory_htaccess_rules&#039;, &#039;edd_custom_modify_htaccess_rules&#039;, 10, 2 );
```