I have installed drupal in my base directory, and am successfully using Clean URLs.

I have some subdirectories I'd like to be able to access via web browser which are not part of the drupal structure. However, attempting to access them when Clean URLs are turned on causes a 404 error.

I don't really know much about mod_rewrite. Is there a simple change that can be made to the rewrite rules in .htaccess which will allow http access to subdirectories?

Comments

cheef@phinu.com’s picture

ooops... I meant "subdirectories" in the Subject title.

Geary’s picture

Drupal's .htaccess does allow you access existing files and subdirectories. This code takes care of that:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Those two RewriteCond lines exclude existing files and directories from the RewriteRule that follows.

However...

.htaccess also contains this line:

# Set the default handler.
DirectoryIndex index.php

which switches the default index file for a directory from index.html to index.php.

I would wager that if you explicitly mention index.html or any existing .html file in one of your subdirectory URLs it will work. It's just when you try to use the subdirectory without index.html that it fails. Is that right?

One thing you can do is rename your index.html files in the subdirectories to index.php. Or you could put this .htaccess file in each of the subdirectories:

# Override Drupal's .htaccess and use index.html here
DirectoryIndex index.html

You could probably add something in Drupal's .htaccess to do the same thing, but this will do the trick.

ronliskey’s picture

You can also string the file extension descriptions together so that index.php and index.html will both work. In the following example Apache looks for index.php and if it doesn't find it, it looks for index.php. Only if it doesn't find either one does it go to 404.

# Set the default handler.
DirectoryIndex index.php index.html
cheef@phinu.com’s picture

mod_rewrite and password protection don't seem to play nice together.

cheef@phinu.com’s picture

I found the solution here:
http://www.webmasterworld.com/forum92/4676.htm

Thanks!

cheef@phinu.com’s picture

actually, it turned out that solution didn't work.
but after some more fun with google, I found a solution that works... making the subdirectories subdomains, so that when they are accessed, mod_rewrite isn't used.

Ems’s picture

The first one is quite easily solved with regular expressions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
----------------------------------------------------------------------
or, to be sure...

# Stuff to let through (ignore)
RewriteCond %{REQUEST_URI} "/excluded-dir"
RewriteRule (.*) $1 [L]

# Stuff to rewrite unless real directory or file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

-------------------------------------------------------
or, to be 200% sure:
# Stuff to let through (ignore)
RewriteCond %{REQUEST_URI} "/excluded-dir"
RewriteRule (.*) $1 [L]

# Stuff to rewrite unless real directory or file or our dir
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/excluded-dir
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

:)

But then we hit the 2nd level - if we have Drupal it tells our browser (in the same .htaccess file) to look for index.php file, otherwise it returns 404 error.

We need to rename this instruction:
DirectoryIndex index.php

... into that:
DirectoryIndex index.php index.html index.htm

And, finally, some of us hit the 3rd level, which is password protection: The above ways to go around the rewrite issue STILL don't work, if the excluded directory is password protected!

The final thing you need to do is to create a 401.shtml file in your home directory. It only needs to contain some decent HTML text (it might be displayed by the user somehow).

And voila - it works.

Took me 5 days to get it all together. :/
Hope this will help the ones after me.