RedirectMatch question

I have requests coming into the server in the following form(s):

http://www.example.org/main/Resource
http://www.example.org/Resource

The base website is installed in the “main” directory and “Resource” changes frequently.

My question:
What is the RewriteMatch code required to force all incoming requests to “http://www.example.org/main/” while allowing all “/Resource” URI nodes to remain within the request string after the last slash in the above-mentioned “main” URL?

Wolf,

As I understand your question, it can’t be done. mod_alias (the Redirect series of directives) is limited to a simple regex match while it looks like you need to test that main is not present in the URI before redirecting (a task mod_rewrite is excellent with).

RewriteCond %{REQUEST_URI} !^main/
RewriteRule .? main/%{REQUEST_URI} [L]

That will send EVERY request to the main directory (if not already there) while preserving the main-less URI.

Regards,

DK

Thanks a bunch, Dave. I think your insight fixed the problem I was up against. I know this approach is probably frowned upon by most professionals out there, but this particular situation dealt with Drupal and a special Domain Access module that did some crazy things with incoming requests. I think your idea fixed it, too, so I’m happy (at least, right now). :slight_smile:

Thanks again!

Wolf,

No worries, mate! There’s a crutch for every problem (once defined).

Regards,

DK