'htaccess redirect with parameter doesn't work

I'm trying to create a redirection from short to real URL but can't find the right way to achieve this:

short URL : mysite.com/aZerTy123

real URL : mysite.com/mypage.html?aZerTy123

I've tried different solutions found here on STOV but the prob remains the same: mypage.html is opened but no way to get the code.

On mypage.html:

let code = location.search.substring(1,location.search.length);
console.log('code='+code)

Opening the real full URL gives code=aZerTy123 as expected but opening it with htaccess gives code= in console ... how to catch it?

My htaccess file:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ mypage.html?$1 [L]


Sources

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

Source: Stack Overflow

Solution Source