views:

127

answers:

8

Hello,

Due to Zend rewriting URL's to module/controller/action, its reporting that images are coming through as a 404.

Here is the error:

  [_requestUri:protected] => /images/Movie/124/thumb/main.png
                [_baseUrl:protected] => 
                [_basePath:protected] => 
                [_pathInfo:protected] => /images/Movie/124/thumb/main.png
                [_params:protected] => Array
                    (
                        [controller] => images
                        [action] => Movie
                        [124] => thumb
                        [module] => default
                    )

                [_rawBody:protected] => 
                [_aliases:protected] => Array
                    (
                    )

                [_dispatched:protected] => 1
                [_module:protected] => default
                [_moduleKey:protected] => module
                [_controller:protected] => images
                [_controllerKey:protected] => controller
                [_action:protected] => Movie
                [_actionKey:protected] => action

Here is my HTACCESS

SetEnv APPLICATION_ENV development

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

I guess what I need todo is put some sort of image or /design detection so its not routing to index.php

Ideas?

+1  A: 

If you use the default directory structure, it should work when you put your images inside the ./public folder.

ArneRie
A: 

Place your images folder inside your public location, and as Arnie mentions you are good to go. The same goes for any additional files you might want to include at any of your views, for example CSS files.

/public
   |__ images/
   |__ css/

Cheers. M.

falomir
They are in public/images
azz0r
A: 

you can try this snippet

 <img src="<?=$this->baseUrl('/img/icon_quickstart.png');?>" alt="start" />
tawfekov
A: 

IN reply to the above

    ArrayObject Object
(
    [storage:ArrayObject:private] => Array
        (
            [exception] => Zend_Controller_Dispatcher_Exception Object
                (
                    [_previous:Zend_Exception:private] => 
                    [message:protected] => Invalid controller specified (img)
                    [string:Exception:private] => 
                    [code:protected] => 0
                    [file:protected] => /Users/aaron/Sites/Eurocreme/eurocreme.com/library/Zend/Controller/Dispatcher/Standard.php
                    [line:protected] => 242
                    [trace:Exception:private] => Array
                        (
                            [0] => Array
                                (
                                    [file] => /Users/aaron/Sites/Eurocreme/eurocreme.com/library/Zend/Controller/Front.php
                                    [line] => 954
                                    [function] => dispatch
                                    [class] => Zend_Controller_Dispatcher_Standard
                                    [type] => ->
                                    [args] => Array
                                        (
                                            [0] => Zend_Controller_Request_Http Object
                                                (
                                                    [_paramSources:protected] => Array
                                                        (
                                                            [0] => _GET
                                                            [1] => _POST
                                                        )

                                                    [_requestUri:protected] => /img/icon_quickstart.png
                                                    [_baseUrl:protected] => 
                                                    [_basePath:protected] => 
                                                    [_pathInfo:protected] => /img/icon_quickstart.png
                                                    [_params:protected] => Array
                                                        (
                                                            [controller] => img
                                                            [action] => icon_quickstart.png
                                                            [module] => default
                                                            [error_handler] => ArrayObject Object
 *RECURSION*
                                                        )

                                                    [_rawBody:protected] => 
                                                    [_aliases:protected] => Array
                                                        (
                                                        )

                                                    [_dispatched:protected] => 1
                                                    [_module:protected] => default
                                                    [_moduleKey:protected] => module
                                                    [_controller:protected] => error
                                                    [_controllerKey:protected] => controller
                                                    [_action:protected] => error
                                                    [_actionKey:protected] => action
                                                )

                                            [1] => Zend_Controller_Response_Http Object
                                                (
                                                    [_body:protected] => Array
                                                        (
                                                        )

                                                    [_exceptions:protected] => Array
                                                        (
                                                            [0] => Zend_Controller_Dispatcher_Exception Object
 *RECURSION*
                                                        )

                                                    [_headers:protected] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [name] => Content-Type
                                                                    [value] => text/html;charset=UTF-8
                                                                    [replace] => 
                                                                )

                                                        )

                                                    [_headersRaw:protected] => Array
                                                        (
                                                        )

                                                    [_httpResponseCode:protected] => 200
                                                    [_isRedirect:protected] => 
                                                    [_renderExceptions:protected] => 
                                                    [headersSentThrowsException] => 1
                                                )

                                        )

                                )

                            [1] => Array
                                (
                                    [file] => /Users/aaron/Sites/Eurocreme/eurocreme.com/application/Bootstrap.php
                                    [line] => 98
                                    [function] => dispatch
                                    [class] => Zend_Controller_Front
                                    [type] => ->
                                    [args] => Array
                                        (
                                        )

                                )

                            [2] => Array
                                (
                                    [file] => /Users/aaron/Sites/Eurocreme/eurocreme.com/library/Zend/Application.php
                                    [line] => 366
                                    [function] => run
                                    [class] => Bootstrap
                                    [type] => ->
                                    [args] => Array
                                        (
                                        )

                                )

                            [3] => Array
                                (
                                    [file] => /Users/aaron/Sites/Eurocreme/eurocreme.com/public/index.php
                                    [line] => 27
                                    [function] => run
                                    [class] => Zend_Application
                                    [type] => ->
                                    [args] => Array
                                        (
                                        )

                                )

                        )

                    [previous:Exception:private] => 
                )

            [type] => EXCEPTION_NO_CONTROLLER
            [request] => Zend_Controller_Request_Http Object
                (
                    [_paramSources:protected] => Array
                        (
                            [0] => _GET
                            [1] => _POST
                        )

                    [_requestUri:protected] => /img/icon_quickstart.png
                    [_baseUrl:protected] => 
                    [_basePath:protected] => 
                    [_pathInfo:protected] => /img/icon_quickstart.png
                    [_params:protected] => Array
                        (
                            [controller] => img
                            [action] => icon_quickstart.png
                            [module] => default
                        )

                    [_rawBody:protected] => 
                    [_aliases:protected] => Array
                        (
                        )

                    [_dispatched:protected] => 1
                    [_module:protected] => default
                    [_moduleKey:protected] => module
                    [_controller:protected] => img
                    [_controllerKey:protected] => controller
                    [_action:protected] => icon_quickstart.png
                    [_actionKey:protected] => action
                )

        )

)
azz0r
A: 

You could try changin your htaccess with

RewriteRule !\.(js|ico|gif|jpg|png|css)$ /index.php

witch shoudl let images and other stuff go thru.

Iznogood
A: 

I'm using the same .htaccess and setup for a Zend project but am not seeing that behavior.

Just some thoughts that might send you down the right path:

  • Case sensitivity in the path?
  • Path doesn't actually exist, causing Apache to pass to index.php?
  • Apache configuration (globally) or at the VirtualHost level
  • Permissions issue? Does main.png at ./public/main.png render when making your request?
  • Overlapping route pattern within application.ini?
  • Disabling the .htacces for a bit, just to see if it's mapping the directories properly?

Just some ideas. -andrew

Inkspeak
+1  A: 

The logic of the .htaccess rewrite rule you have set there is that if it can't find the file, it will send the request to index.php instead. Which means that if your images aren't reachable (not in the public directory) zend_framework will try to handle it. Which it of course can't.

Thomas Winsnes
A: 

You have to add the line RewriteCond %{REQUEST_FILENAME} -f

Cyril