Search code examples
php.htaccesshyperlinkget

I want to make my long reference link dynamic with htaccess


First of all, I have a link that takes 2 parameters;

http://localhost/project/home.php?SK=2&referance=1

?SK=2 is my first parameter and &referance=1 is my second parameter. The SK=2 parameter draws my files in the php file, and the referance=1 parameter prints the value from the get method to my registration page. What I want is to put this link in below format with htaccess

http://localhost/project/register?referance=1

The link I made before brings my register page, but now I want it to bring the reference code, but unfortunately it doesn't.

Htaccess code I used before;

RewriteRule ^register$ home.php?SK=2 [NC,L]

Solution

  • RewriteRule ^register$ home.php?SK=2 [NC,L]
    

    You just need to add the QSA (Query String Append) flag to your existing rule.

    For example:

    RewriteRule ^register$ home.php?SK=2 [QSA,NC,L]
    

    This will now rewrite /register to /home.php?SK=2 and /register?referance=1 to /home.php?SH=2&referance=1.

    Reference: