Apache - How to get resources from the context path and not default when trying to get from /

453 views Asked by At

I have various web application running on my apache server.

I can access the first web app by using http://localhost:8080/app1/login

But within the login page, I am trying to access an image, login.png as "/images/login.png". This tries to get the images from the default web app and not the web app on which it is currently working from.

I do not want to change the default web app of apache. Is there a way that I can access the image like "/images/login.png" and not as "/app1/images/login.png" or "../images/login.png"

2

There are 2 answers

2
Dennis Meissner On BEST ANSWER

Or if you want to use a RewriteRule add this to your webserver roots .htaccess. This checks if the Requested filename is not a physical file or directory. if it's not. it redirects to your /app directory

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^/images/(.*) /app1/images/$1 [L,QSA]
</IfModule>
0
Dusan Plavak On

well if you are using it in html... then

./images/login.png

EDIT: Sorry I didnt see that you dont want to use that path... as other option can be using modRewrite... you can rewrite your paths... so if you will use /login/image.jpg that can apache automatically rewrite for you as ./login/image.jpg