beta beta - 2 months ago 6
Apache Configuration Question

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

I have a domain named

domain.com
. I cannot change the document root, but the files for the webpage are in a subfolder named
folder
. 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.)?domain.com$
RewriteRule ^(/)?$ folder/$1 [PT,L]


Now I wanted to create an HTML page showing a simple image (
logo.png
), which is located in
folder
(path:
[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
folder
from the user.

Can this be done by changing my htaccess?

Answer

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]
Comments