Apache doesn’t catch the below .htaccess rule if requests are made by relative paths.
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(.*)/?$ index.php?var=$1 [NC,L]
E.g. if the HTML sent to the client includes:
<link href="CSS/main.css" rel="stylesheet" type="text/css" />
Apache will skip the rule. If however the HTML includes:
<link href="http://host.com/CSS/main.css" rel="stylesheet" type="text/css" />
it works just fine.
The same goes for relative paths inside e.g. CSS files, like:
background-image:url(../images/image.png);
that is, if the requested CSS has first been requested with the full path name.
How is this possible?
The second RewriteRule will only rewrite the search path internally, on the server that is. So, when a relative search path is sent to the client, say:
whatever is referred to as
$1in the second RewriteRule will be included in the search path.So, if e.g. http://www.example.com/en/ is requested by the client and a HTML document including the relative path
href="CSS/main.css"is sent back, the client will expect the css file to be located inwww.example.com/en/CSS, notwww.example.com/CSS/. Naturally then if the css document in the example is referred to with a direct path like:href="http://example.com/CSS/main.css"the document will be correctly retrieved.