By cheef@phinu.com on
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
er, I meant "subdirectories"
ooops... I meant "subdirectories" in the Subject title.
It should work as is, except for index.html
Drupal's .htaccess does allow you access existing files and subdirectories. This code takes care of that:
Those two RewriteCond lines exclude existing files and directories from the RewriteRule that follows.
However...
.htaccess also contains this line:
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:
You could probably add something in Drupal's .htaccess to do the same thing, but this will do the trick.
You can also string the file
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.
The problem are the directories are password protected.
mod_rewrite and password protection don't seem to play nice together.
I found the solution
I found the solution here:
http://www.webmasterworld.com/forum92/4676.htm
Thanks!
actually, it turned out that
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.
There are actually 3 levels of this issue
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.