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

StackOverflow https://stackoverflow.com/questions/18506664

  •  26-06-2022
  •  | 
  •  

Question

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"

Was it helpful?

Solution

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>

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top