Site location: http://localhost/~username/website
The website loads lots of images with an absolute url such as /image/image.png.
I need that request to go to: http://localhost/~username/website/image/image.png instead of http://localhost/image/image.png.
I also need this to not affect any other folders or the root folder. So that I could also access http://localhost/image/image.png if I wanted to.
Is there some way of making it so that when it's requested from this subfolder to redirect?
I want the absolute reference like /css/something.css and /image/image.png to points to /subdirectory/css/something.css and /subdirectory/image/image.png. That way I don't have to rewrite all the absolute references. So, I don't want to modify the root directory.
I'm wondering if setting up a virtual host that would not allow the subdirectory "website" to have no ability to access the root. I don't ever need root access from this folder.
You can use this rule in root .htaccess OR in Apache/vhost config:
Be sure you are allowed to use .htaccess file in your webserver. Look at this how to enable in apache: https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file
Create a .htaccess file in root or ~username/website directory Then write this to your .htaccess file:
Why the requirement to use
/image/image.png
? Why wouldn't you just use one of these instead: