beta beta - 22 days ago 4x
Apache Configuration Question

htaccess redirects to subdomain: how to create links and images in HTML?

I have a domain named
. I cannot change the document root, but the files for the webpage are in a subfolder named
. When I access the url via a browser, I want the webpage to be loaded from the subfolder. Hence, I created the following htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteRule ^(/)?$ folder/$1 [PT,L]

Now I wanted to create an HTML page showing a simple image (
), which is located in
[document root]\folder\logo.png
). When I load the page in the browser, the image is not loaded. The HTML looks like this:

<img src="/logo.png">

Obviously, if I change the HTML to:

<img src="/folder/logo.png">

it works. However, I want to hide the existence of
from the user.

Can this be done by changing my htaccess?


Your rule is only working for the landing page. Change your rule to:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^(?!folder/)(.*)$ folder/$1 [NC,PT,L]