mod_rewrite

By donmc, 24 August, 2008
Topic

From: http://forums.whirlpool.net.au/forum-replies-archive.cfm/813573.html

Think about what your rewrite rules mean. They are saying: if /folder1 or /folder2 appears anywhere in the URI, stick drupal/ onto the front.

So say somebody goes to /folder1/page. Apache rewrites that to /drupal/folder1/page (assuming your RewriteBase is /), then it does an internal redirect. So now Apache has got the URI /drupal/folder1/page. Apache rewrites that to /drupal/drupal/folder1/page, then it does an internal redirect. And so on.... Apache gives up after a set of number of internal redirects.

Remember, [L] means "stop processing any more rules on this request", it does not mean "stop processing any more (internal or external) redirects". So each internal redirect starts the rule processing from the top, since they're each new subrequests.

What you need to do is make the rewrite rule only apply when /folder1 and /folder2 are at the front of the URI. To do this, prepend their regular expressions with ^:

RewriteCond %{REQUEST_URI} ^/folder1 [OR]
RewriteCond %{REQUEST_URI} ^/folder2
RewriteRule (.*) drupal/$1 [L]

Actually, I would rewrite that completely:

RewriteRule ^(folder[12]/.*) drupal/$1 [L]

Much simpler. However I'm guessing folder1 and folder2 were just examples... right?

(And if you're wondering where the leading / went in that last RewriteRule... when used in an htaccess file, RewriteRules match against the URI after the removal of the RewriteBase. %{REQUEST_URI} is always the entire request URI.)