Linux

Home

Allow access to a non-Drupal directory

If you install drupal into your root directory and have directories that were created outside of drupal, when you try and access the non drupal directory such as something.com/somedir  you will recieve a "The requested page "/something" could not be found." from drupal despite the fact that the directory somesite.com/something
does really exist. You need to edit you .htaccess that is in your root directory, you can use vim if you are comfortable in a shell or you can access your hos via ftp copy the .htaccess fiel off edit it then copy it back to your root firectory once you finishes editing it the choice is yours.

If you use nautilus file manager you will need to do ctrl+h or click View then select Show Hidden Files in order to see the .htaccess file to open it as it is a hidden file. Once you got the file open for editing you will need to add the following section:

user@something.com [~/public_html]#vim .htaccess [RETURN]

<IfModule mod_rewrite.c>
  RewriteEngine on

  ###############################################
  ###    ACCESS TO NON DRUPAL DIRECTORIES       ###
  ###############################################

  RewriteCond %{REQUEST_URI} "/somedir/"
  RewriteRule (.*) $1 [L]
  DirectoryIndex index.php index.html index.htm
  Options +Indexes

  ###############################################
  ###    END OF NON DRUPAL DIR SECTION               ###
  ###############################################

:wq

 

Once you finished editing the .htaccess file copy it back to your root directory & now when you try and access somesite.com/somedir you will now see the contents of that directory whether it be a webpage or some documents etc and will no longer see the drupal 404 error.

 


 

Allow access to protected non-drupal directory

In a previous article here we explained how to regain access to your non-drupal created directories by editing the root .htaccess file. When i first came across this issue i thought i could just give access to the protected directory in the same way i did a non protected directory & it would then just prompt me for the username & password when i tries to access the directory that is protected.

This is not the case however, you do need to take the same steps as in the previous article but you also need to take a second step, the second step is to edit the .htaccess within the subdirectory itself, this will have been created when you protected that subdirectory. So copy the subdirectories .htaccess then edit it to contain the following lines which will tell drupal to ignore this directory.

user@something.com [~/public_html/somedir]# vim .htaccess

### the following allows users in to this directory without drupal interfering ###
ErrorDocument 401 "Unauthorized"

AuthType Basic
AuthName "somedir"
AuthUserFile "/home/user/.htpasswds/public_html/somedir/passwd"
require valid-use

 

The line ErrorDocument 401 "Unauthorized" tells drupal to ignore this directory thus allowing apache2 to handle it's permissions again, allowing you to be promoted for a username & password when navigating to this protected directory as previously. The 4 Auth lines are the existing .htaccess so you should only be adding the 1 ErrorDocument line.

When i ran into this problem i found many articles explaining how to regain control of a protected non-drupal directory from fairly simple to so over the top complex they would make your eyes water, this solution is 1 line & about as simple as it gets.