Community

load php and html files in non-drupal directories with .htaccess

I have several hundred of files in a few different directories which need to be loaded outside of drupal 7. Some are .php and some are .html. I need these files to load without drupal.

For example:

The root is: example.com
I need to load all of the files in the directory: example.com/news/archives/
There are hundreds of files in there which need to load as-is, without tying into drupal.

Based on the instructions at http://drupal.org/node/30334 I added these lines to my root level .htaccess file:

# stuff to let through (ignore)
  RewriteCond %{REQUEST_URI} "/news/archives/"
  RewriteRule (.*) $1 [L]

... but I'm getting a 500 internal server error.

I also have files in other directories which will need the same setup. For example: example.com/level1/mypage.html, which I'm assuming will need a similar setting in the .htaccess file, but I'm not sure how to set it up.

Any suggestions, please?

Comments

Are you sure you need

Are you sure you need this?

Before proceeding with these instructions, note that you almost never need these rewrites. Neither for Apache aliases nor for all the usual kinds of applications running in subdirectories.

When Drupal appears to take over your subdirectories, it actually takes over the pages where Apache would respond with a "Page not found" error anyway.

For example.com/level1/mypage.html you wouldn't need anything, Apache will simply serve that file. If you need a directory listing for example.com/level1/, you should use "Method 2 - Allow html (and folder listings) in the subdirectory" by placing a .htaccess in that folder.

I wouldn't say I'm "sure" I

I wouldn't say I'm "sure" I need this, but I can't think of a better way. Here's what I'm facing...

My current site is built with some standard .php and .html files. I have a page located at example.com/news. I also have a page at example.com/news/archives. And I have hundreds of pages at example.com/news/archives/12391.php, etc.

In my new drupal build, I have a page called 'news' at the same address as the old site. I need that to load via drupal. Same for the 'archives' page. However, I don't want to load every one of the hundreds of archives/12391.php pages into drupal. I just want them to stay in the 'archives' directory like they are on the current site.

With the default drupal .htaccess settings, when I browse to example.com/news, I get a redirect loop error. I'm guessing that's because I have a 'news' page and I also have a 'news' directory.

My goal is to keep some of the old content working. They're not pages that 'fit' into the drupal framework, but need to function as standalone pages.

I did figure out that if I place an .htaccess file in the 'news/archives/' directory and turn RewriteEngine Off, the files will load. However, I'm not sure this is the best way to accomplish what I need since I have numerous other directories which will need the same setup. I'm thinking there must be a way within the root .htaccess file to accomplish the same thing by listing the directories I need to affect, instead of having a bunch of .htaccess files in various directories which do nothing more than turn off the RewriteEngine.

I hope this isn't totally confusing you.

Method 2 seems to work...

Method 2 seems to work... mostly.

Placing .htaccess in the /example.com/news/archives directory does the trick with the following code:

DirectoryIndex index.php index.html index.htm
Options -Indexes

However, when I go to example.com/news, I get a "redirect loop error". I have a page node with an alias of /news, but I also have a directory name /news. Apparently, they don't like each other very much.

How can I make the /news alias work even though I have a /news directory?

Hm, I see your problem. But

Hm, I see your problem. But that means you definately don't want the option you described first, because that is meant to leave the path to something other than Drupal, where you want Drupal to take over that path despite the existing folder.

I guess you can use something like this instead to make sure those folder names go to Drupal's index.php:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_URI} "/folder1/" [OR]
  RewriteCond %{REQUEST_URI} "/folder2/"
  RewriteRule ^ index.php [L]

Any other thoughts on this?

Any other thoughts on this? Using the default .htaccess settings, the archives pages load (example.com/news/archives/v1i22.php)

But when I load the drupal node with the alias of example.com/news/ and the node with the alias of example.com/news/archives, I get a redirect loop error. Not only are those aliases, but they are also directories at the root of my drupal installation.

If I rename the directories to something other than /news/ and /news/archives/, the alias pages load, but obviously that breaks the URL to the .php pages within the /archives/ directory.

I changed the root .htaccess file to include:

RewriteCond %{REQUEST_URI} "/news/" [OR]
RewriteCond %{REQUEST_URI} "/news/archives/"
RewriteRule ^ index.php [L]

...but that doesn't do the trick.

I'm stumped.

Is there a way in the code above to tell .htaccess to match EXACTLY what the condition is? Because won't the RewriteCond match anything that 'includes' /news/ or /news/archives/?

nobody click here