php - Bypass other .htaccess files after RewriteRule -
the problem facing related cakephp , explain in context mod_rewrite issue:
in cakephp, requests routed /app/webroot
directory. in directory, have directory called assets
in user-uploaded files stored. want able serve thumbnails every image in folder, , want auto-generate , cache them on first request.
to that, have .htaccess
file in assets
directory, supposed route requests start thumbs/
phpthumb script. put said script assets
directory , work fine. but:
- i want avoid file bloat (as there can multiple resolution thumbnails , on) , therefore rather store thumbnails in
/app/tmp
directory, - the whole thing part of cakephp plugin developing, neat if script stay in plugin's folder.
what have tried (inside /app/webroot/assets
directory):
rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^thumbs\/([^\/]*)\/(.*)$ ../../plugin/myplugin/lib/thumbnail.php?size=$1&path=$2 [qsa,l,s=2]
now doesn't work. problem .htaccess
files in /app
, /app/webroot
route /app/webroot/index.php
(or physical file in webroot
). s
flag seems apply rules in same file.
i change files allow thumbnail.php
said, part of plugin , prefer keep configuration-less possible.
so question: there way bypass/disable other rewrite rules after 1 in /app/webroot/assets/.htaccess
applied?
problems
there 2 big-ish problems in code in question:
- mixing mod rewrite with, frontcontroller-style php code
- trying route php file supposed inaccessible
the php file supposed web accessible production cakephp application webroot/index.php
create controller action
the right way you're asking create route , controller action:
route:
<?php // app/config/routes.php router::connect( '/thumbs/*, array('controller' => 'thumbs', 'action' => 'serve') );
controller:
<?php // app/controller/thumbscontroller.php class thumbscontroller extends appcontroller { function serve() { // resize file, //(preferably write request uri) //and serve image } }
the controller action can use send-file (or media views in older versions) send file contents after resizing.
cache in web-accessible path
note serving files php is slow:
it’s known fact serving assets through php guaranteed slower serving assets without invoking php.
if @ possible, make sure request thumb image processed , written same url request (or different location, appropriate edit .htaccess file - here's example) next time same image requested - served directly via apache. if caching technique implemented in form whereby php part of request cached image - caching not going particularly effective.
Comments
Post a Comment