Basically, I have a directory /website.com/ that contains an index.php.
What usually happens is that I have an htaccess file that redirects the URL to the index, so something like
domain.com/api/
Would load
domain.com/index.php?uri=api/
But now say, instead of having a sub-directory, I want to use a sub-domain, like:
api.domain.com
Would run:
domain.com/index.php?uri=api/
My current approach almost works. My htaccess file looks like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^api
RewriteRule ^(.*)$ index.php?uri=api/$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?uri=$1 [L,QSA]
Which works fine for the URL part. But the problem comes in when I’m trying to load an image.
Basically, instead of loading from the base directory, it’s appending the directory onto the URL.
So when I request an image on api.domain.com/v1/ it’s trying to load the image from
domain.com/v1/image.png
rather than
domain.com/image.png
Does anyone know how to fix this issue?
The solution I think I found was to use absolute URL’s rather than relative ones when including the image (in my CSS).
So rather than
I used
Not my ideal solution but it is a workaround. If someone has a better way to solve my problem, I will gladly use.