Hooking up a Front Controller under Apache...
Moderator: General Moderators
Hooking up a Front Controller under Apache...
I'd like to start putting my new Front Controller through its paces.
I've been reading several sites about different ways to "register" the Front Controller script with Apache (1.3 family) and I'm not finding anything that is likely to work well.
My "requirements":
1. This front controller should be invoked for all *.php requests (I can't use a custom extension with my fallback code.)
2. The entire application is normally installed at the top level of the domain -- so no extra directory fake like a ForceType is possible.
3. I need the original URI available, preferrably not rewritten into a GET parameter.
1&2 seem to rule out the Handler/AddHandler based methods.
2 rules out the ForceType method
I don't know mod_rewrite, it might be able to work?
I've been reading several sites about different ways to "register" the Front Controller script with Apache (1.3 family) and I'm not finding anything that is likely to work well.
My "requirements":
1. This front controller should be invoked for all *.php requests (I can't use a custom extension with my fallback code.)
2. The entire application is normally installed at the top level of the domain -- so no extra directory fake like a ForceType is possible.
3. I need the original URI available, preferrably not rewritten into a GET parameter.
1&2 seem to rule out the Handler/AddHandler based methods.
2 rules out the ForceType method
I don't know mod_rewrite, it might be able to work?
Hmm, that might work. I'll play with it and see....
Hmm Looks like it would work for all but the virtual directories...
OK, maybe I need to give up on the legacy fallback, its causing enough problems with the FrontController's design, plus it greatly complicates hooking everything up. Hmm time to ponder things....
Hmm Looks like it would work for all but the virtual directories...
OK, maybe I need to give up on the legacy fallback, its causing enough problems with the FrontController's design, plus it greatly complicates hooking everything up. Hmm time to ponder things....
I was just testing out setting the custom 404 handler to the same script as auto-prepend; hoping it would catch the virtual directories. However it loses the REQUEST_URI and PATH_TRANSLATED then, so I can't get back to the request (not to mention the havoc it causes with the error logs.)
Any ideas how to make auto-prepend work with virtual directories and my above requirements?
Any ideas how to make auto-prepend work with virtual directories and my above requirements?
Can you think of any way to avoid the use of the custom 404 handler, but still meet my requirements? Since the numberr of pages triggering the 404 is only going to grow as I migrate scripts to the new frameowrk.
I'm considering a mod_rewrite approach like:
In my production server there would be no basse dir, but in testing I tend to have mutliple branches installed at different locations.
Would there be any downside to using Mod_rewrite in this manner? I suspect it will limit the usefulness of my logs... but at least the error log wouldn't be getting cluttered.
I'm considering a mod_rewrite approach like:
Code: Select all
RewriteEngine On
RewriteRule ^BaseDir/(.*) BaseDir/FrontController.php [E=APP_REQUEST:$1]Would there be any downside to using Mod_rewrite in this manner? I suspect it will limit the usefulness of my logs... but at least the error log wouldn't be getting cluttered.
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
when I've done a 404 handling, I've used a code like$_SERVER should have the original requesting URI in it..
Code: Select all
RewriteCond ${REQUEST_FILENAME} !-d
RewriteCond ${REQUEST_FILENAME} !-s
RewriteCond ${REQUEST_FILENAME} !-l
RewriteRule .* /control.phpI seem to be settling on:
I needed the [/|\.php] to make sure index pages still worked and to stop it from messing with the CSS, images, and static XHTML.
While I could get the request out of REQUEST_URI, this helps make the rest of the code self-configuring. I have to configure the RewriteRule on the server no matter what, so embedding the path information here seems to make some sense.
I'll need to find a solution to fact that some of the subdirectories .htaccess files aren't exected now, but I'm sure I can a work-around (need to set custom include_paths, so ini_set will be my friend.....)
Code: Select all
RewriteRule ^/~nielsene/cib/main-dev(.*)([/|\.php])$ /~nielsene/cib/main-dev/FrontController.php [E=APP_REQUEST:$1$2,PT]While I could get the request out of REQUEST_URI, this helps make the rest of the code self-configuring. I have to configure the RewriteRule on the server no matter what, so embedding the path information here seems to make some sense.
I'll need to find a solution to fact that some of the subdirectories .htaccess files aren't exected now, but I'm sure I can a work-around (need to set custom include_paths, so ini_set will be my friend.....)