Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite ruleset processing order

problem managing/enforcing order of rewrite rules

         

toothhole

9:47 am on Sep 14, 2007 (gmt 0)

10+ Year Member



Hello all,

In apache2, I need to enforce one single rewrite rule in the global config. No matter what I tried so far, I am unable to make the global rule be processed before a .htaccess-based ruleset inside a vhost docroot jumps in.

The rule is actually very simple and is used to redirect phpmyadmin to an external URL:
RewriteRule ^(.*/)?phpmyadmin(.*)/ [ex.tern.al...] [R=301,L,NC]

Hence I think the problem is located in the order rules(ets) are being applied.

Can some enlighted soul please point me to a page where I can find information on how this can be done?

TIA,
th

jdMorgan

12:45 pm on Sep 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would suggest that you use an Alias directive to do this, since lower-level .htaccess files can override higher-level configuration files if they are allowed to execute.

You can alias the 'special' URLs, proxy them to another server, or both.

Jim

toothhole

1:20 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



Hello Jim,

Thank you for your answer. Setting up mod_proxy is something I'm trying to avoid.
Your good hint for 'Alias' indeed lead me to 'RedirectMatch' which I'm going to try now. Alias does internal redirects, while Redirect does external redirects. As I understand the docs, this is something I have to add to every vhost. Not a problem, but less elegant than Rewrite (in theory since it doesn't work).
Is there no way to administratively enforce rewrite rules?
Like phpadminvalue for PHP?

Cheers,
th

jdMorgan

1:34 pm on Sep 14, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The order of execution of directives is complex and varies depending on the server version and the module load order -- I get a headache just thinking about thinking about it. There is documentation on the Apache site that describe how it works.

You don't have to 'set up a proxy' to do what you're describing; Apache pretty much comes out of the box with a reverse proxy enabled, and that's all you need. So you don't have to deal with the security headaches of configuring/enabling a forward proxy at all. Just as an example of the 'ready to go' nature of the reverse proxy, see RewriteRule's [P] flag in mod_rewrite -- It works without any special configuration requirements. (I'm citing this as an example of support only, acknowledging that it doesn't address your problem of execution order.)

Take a close look at the reverse proxy documentation [httpd.apache.org] -- In conjunction with mod_alias, I believe you'll find a relatively simple solution to your problem.

I got into this subject "from the other end" after discovering that on most servers it's impossible to prevent mod_proxy from getting control before mod_rewrite does, and while I think that info will be useful to you, that's also the limit of my knowledge on the subject... :)

Jim

toothhole

2:16 pm on Sep 14, 2007 (gmt 0)

10+ Year Member



Hello Jim,

Thanks again for the valuable input. I never thought about all those different ways of dealing with redirects. Surely I will dig a bit deeper into that, especially the reverse proxying.
For now, I'm happy because a very simple solution works perfectly. I just made the global rewrite a global redirectmatch:

RedirectMatch ^(.*/)?phpmyadmin(.*)/ [ex.tern.al...]

And this gets processed prior to a vhosts .htaccess (rewrite) rules.

Weekend saved :-)

Cheers,
th