Remove unwanted query string generated at the end of URL
In order to remove "index.php?dir=" from links, I use the following htaccess and it works just fine:

    RewriteEngine on
    RewriteBase /folder
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ index.php?dir=$1 [L,QSA]

The issue is that if a dir is formatted without a slash at the end, like

    http://www.example.com/folder/dir1/dir2

then an unwanted query string shows at the end like

    http://www.example.com/folder/dir1/dir2?dir=dir1/dir2/

Sure this opens the intended directory but with the unwanted query at the end.

Please advice?
Remove unwanted query string generated at the end of URL
===

In order to remove "index.php?dir=" from links, I use the following htaccess and it works just fine:

    RewriteEngine on
    RewriteBase /folder
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.*)$ index.php?dir=$1 [L,QSA]

The issue is that if a dir is formatted without a slash at the end, like

    http://www.example.com/folder/dir1/dir2

then an unwanted query string shows at the end like

    http://www.example.com/folder/dir1/dir2?dir=dir1/dir2/

Sure this opens the intended directory but with the unwanted query at the end.

Please advice?