'.htaccess rewrite only if file/folder doesn't exist bug [duplicate]

I am trying to make .htaccess rewrite only if a file or folder doesn't exist, I got that part down with this:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.*)$ index\.php?var=$1 [QSA,L]

However I am running into an issue where if I go to https://server/nonexistentfolder/secondnoneexistentfolder it will display index.php as if it was in that second non existent folder, which would then break all the links in the html document. How can I make index.php rewrite as if it was in the root directory?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source