.htaccess - Symfony 2 404 Custom page for missing resource -


so, have been trying add 404 controller in case image missing , need go , it.

initially, tried notfoundhttpexception/resourcenotfoundexception listener loaded class deal it. worked great, if symfony2 routing issue.

problem is, isn't. /web/bundles/mysite/images/missingimage.jpg 404, handled apache seems.

so .htaccess tried:

<ifmodule mod_rewrite.c>     rewriteengine on      rewritecond %{request_uri}::$1 ^(/.+)/(.*)::\2$     rewriterule ^(.*) - [e=base:%1]      rewritecond %{env:redirect_status} ^$     rewriterule ^app\.php(/(.*)|$) %{env:base}/$2 [r=301,l]      rewritecond %{request_filename} -f     rewriterule .? - [l]      rewriterule .? %{env:base}/app.php [l]      errordocument 404 /web/404.txt </ifmodule> 

just see if work, feeling wouldn't , didn't.

so how can setup forward symfony2 page when encounters 404 within /web folder.

i guessing should .htaccess, not having look.

in end, want go to:

/web/app.php/fourzerofourhandler/web/bundles/mysite/images/missingimage.jpg 

or:

/web/app_dev.php/fourzerofourhandler/web/bundles/mysite/images/missingimage.jpg 

depending on whether in prod or dev.

and ideas?

you have 2 options.

first 1 route images via symfony2 app. liipimaginebundle in order generate thumbnails. redirect 404 custom error page. downside static image whole symfony2 kernel needs booted. that's time , resource expensive.

the second option redirect apache2 route unknown or route throws 404 / httpnotfoundexception:

/*  * @route('/404', name="not_found")  */ public function notfoundaction() {     return new httpnotfoundexception(); } 

that gives more control on error message since can render twig template or log error message.


you right. had trouble custom controller when inserted errordocument in .htaccess. solution edit vhost instead. go /etc/apache2/sites-available , select file (by default it's called default) virtual host ist stored. replace allowoverride option in <directory>. , replace these lines:

   allowoverride fileinfo    errordocument 404 /not_found.html 

solution found here. don't forget reload apache configuration:

sudo service apache2 reload 

Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -