I'm new to this (wonderful) website!
I did search for an answear to my problem but I could not find it.
(Q: bad english. A: I'm italian, sorry.)
My goal:
I would host in a domain 2 different websites, each of them using their proper htaccess rules.
The structure:
/index.html --> empty page.
/site1/index.html
/site1/styleA.css
/site1/logo.png
/site2/index.html
/site2/styleB.css
/site2/logo.png
The problem:
/site1/index.html gets the stylesheet file using absolute path:
<link rel="stylesheet" type="text/css" href="/style.css" />
this way it try to get the "style.css" file in the root directory (404).
Same problem with site2 and every other file that use absolute path.
More info:
The Question:
Is it possible to solve the 'absolute path' problems using only .htaccess file(s)?
If not, what would you suggest me to do?
I suppose you can check the referer:
RewriteEngine On
RewriteCond %{HTTP_REFERER} /site1/
RewriteCond %{REQUEST_URI} !^/site1/
RewriteRule ^(.*)$ /site1/$1 [L]
RewriteCond %{HTTP_REFERER} /site2/
RewriteCond %{REQUEST_URI} !^/site2/
RewriteRule ^(.*)$ /site2/$1 [L]
This doesn't redirect the browser, so there's a possibility that the browser will cache a "/style.css" and the two sites get mixed, so you may want to redirect the browser instead by changing the flags from [L]
to [L,R]
.