How to maintain relative urls in a Apache subfolder?

59 Views Asked by At

I have a static website with urls that look like this:

"src/assets/images/image.png"

I have copied my site into a game subfolder in public_html on my Apache host.

When I load this from the domain, all the links break with 404s that looks like this:

https://dev.mydomain.com/src/assets/images/image.png

The correct url should, of course, be this:

https://dev.mydomain.com/game/src/assets/images/image.png

My question is: How can I inject the /game/ into the url, without having to rewrite my source code. Is this even possible?

Note that I have tried this as a possible solution: https://www.siteground.com/kb/how_to_change_my_document_root_folder_using_an_htaccess_file/. It "worked" but as a side-effect it also re-routed dev.mydomain.com to dev.mydomain.com/game, which knocked out my main site.

I'm a complete Apache novice, so any help greatly appreciated! :)

1

There are 1 best solutions below

0
On

This did it:

 # Map game URLs (/src --> /game/src)
 RewriteCond %{DOCUMENT_ROOT}/game%{REQUEST_URI} -f [OR]
 RewriteCond game/%{REQUEST_URI} -d
 RewriteRule (.+) game/$1 [QSA,L]