Write .htaccess file to configure subfolder as documentroot

.htaccessapache-2.2

I have the following directory structure. /var/www/html is the DocumentRoot.

var
  www
    html
      demo
        css
           abc.css
        js
           abc.js
        index.html

How can I write an .htaccess file in the "demo" folder such that all resources in that folder think that "demo" is the documentRoot instead.

ex: http://myserver.com/demo/css/abc.css should work.

In the code of index.html, I just want to refer to the CSS files this way:

<link href="/css/abc.css" media="screen" rel="stylesheet" type="text/css">

instead of "/demo/css/abc.css"

Best Answer

Try this. Works for me.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mysite.com$
RewriteCond %{REQUEST_URI} !folder/   #<---  Here.
RewriteRule (.*) /folder/$1 [L]       #<-- and here. 
Related Topic