Url of image not working

Hi,

I use the yii advanced template. I store the images in the root/public directory, because it will be an image intensive application. But I do not know how I can render out the image on the web page.

This is my structure.




/root

  /backend

  /common

  /fronted

  /public/

     /user/

        /image/

           default_user.jpg



For example I do not know what is the url of my default_user.jpg.

Because this url path does not work:




myapplication.dev/public/user/image/default_user.jpg



It seems I missing something.

Your webserver is probably configured to route all requests to frontend/web/index.php. So to serve your image directory, you’d have to tell it to route specific requests to another directory.

For example every URL that starts with "public".

You are right.

Can you help me how I should write this rule to render my image:


http://myproject.dev/public/user/image/default_user.jpg

?

I have tried in this way, but this is not work:




   <VirtualHost *:80>

       ServerName myproject.dev/public

       DocumentRoot "/var/www/html/myproject/public/"


       <Directory "/var/www/html/myproject/public/">

           # use mod_rewrite for pretty URL support

           RewriteEngine on

           # If a directory or a file exists, use the request directly

           RewriteCond %{REQUEST_FILENAME} !-f

           RewriteCond %{REQUEST_FILENAME} !-d

           # Otherwise forward the request to index.php

           RewriteRule . index.php


           # use index.php as index file

           DirectoryIndex index.php


           # ...other settings...

       </Directory>

   </VirtualHost>


   <VirtualHost *:80>

       ServerName myproject.dev

       DocumentRoot "/var/www/html/myproject/frontend/web/"


       <Directory "/var/www/html/myproject/frontend/web/">

           # use mod_rewrite for pretty URL support

           RewriteEngine on

           # If a directory or a file exists, use the request directly

           RewriteCond %{REQUEST_FILENAME} !-f

           RewriteCond %{REQUEST_FILENAME} !-d

           # Otherwise forward the request to index.php

           RewriteRule . index.php


           # use index.php as index file

           DirectoryIndex index.php


           # ...other settings...

       </Directory>

   </VirtualHost>



No need for a second vhost.

Just add this to your Yii vhost:




    Alias "/public" "/var/www/html/myproject/public"

    <Directory /var/www/html/myproject/public>

        Require all granted

    </Directory>



Remove/Comment the first vhost completely before trying.