0

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]
Wolden
  • 195
  • 1
  • 12
  • 2
    Javascript runs on client side only and your rewrite is happening in web server. To be able to fetch query string you need to use backend script like php, perl, python etc – anubhava Apr 12 '22 at 11:50
  • thanks for answer. Sorry don't exactly understand what you mean: it should work with "mypage.php/code" ? see : https://stackoverflow.com/questions/21662957/htaccess-redirect-directory-name-to-parameter – Wolden Apr 12 '22 at 11:56
  • works with `let code=location.href.split("/").slice(-1);` console.log('code='+code) // code=aZerTy123 – Wolden Apr 12 '22 at 12:22
  • That's not query string btw – anubhava Apr 12 '22 at 13:36

0 Answers0