diff --git a/includes/file.inc b/includes/file.inc
index 6e2e5cb..f5d46d9 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -479,6 +479,11 @@ function file_ensure_htaccess() {
  *   The default is TRUE which indicates a private and protected directory.
  */
 function file_save_htaccess($directory, $private = TRUE) {
+  // Don't create .htaccess files if 'no_htaccess' variable is TRUE.
+  if (variable_get('no_htaccess', FALSE)) {
+    return;
+  }
+
   if (file_uri_scheme($directory)) {
     $directory = file_stream_wrapper_uri_normalize($directory);
   }
diff --git a/modules/simpletest/tests/file.test b/modules/simpletest/tests/file.test
index 3633bae..d010d80 100644
--- a/modules/simpletest/tests/file.test
+++ b/modules/simpletest/tests/file.test
@@ -951,6 +951,17 @@ class FileDirectoryTest extends FileTestCase {
     // Verify contents of .htaccess file.
     $file = file_get_contents(file_default_scheme() . '://.htaccess');
     $this->assertEqual($file, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006\nOptions None\nOptions +FollowSymLinks", t('The .htaccess file contains the proper content.'), 'File');
+
+    // Remove .htaccess file to then test that it does not get re-created when no_htaccess=TRUE.
+    @drupal_unlink(file_default_scheme() . '://.htaccess');
+    $this->assertFalse(is_file(file_default_scheme() . '://.htaccess'), t('Successfully removed the .htaccess file in the files directory.'), 'File');
+    variable_set('no_htaccess', TRUE);
+    file_ensure_htaccess();
+    $this->assertFalse(is_file(file_default_scheme() . '://.htaccess'), t('Did not re-created the .htaccess file in the files directory (no_htaccess=TRUE).'), 'File');
+
+    // Create .htaccess file for remaining tests.
+    variable_del('no_htaccess');
+    file_ensure_htaccess();
   }
 
   /**
