so I'm working on this project where I need to make a referral module. I have to rewrite the URL in such a way, that the page refer_handler.php?refhash=(base64encode(email)) re-writes to /refer/(base64encode(email))
I have this code for the redirect :-
RewriteRule ^refer/(\d+)$ refer_handler.php?refhash=$1 [L,QSA]
Here's the refer_handler.php
<?php
session_start();
include 'dbconnector.php';
include 'inc/inc.functions.php';
include 'dbpdo.php';
if((isset($_SESSION['logged'])) && ($_SESSION['logged']=1))
{
//get the email id from the header
$emailOfTheReferrer = $_REQUEST['refhash']; // we get the refhash from here.
echo base64_decode($emailOfTheReferrer);
////////////////
//Layers -- //
//Check if the refer hash exists (Check if the parent email exists)
}
else
{
header('Location:../index');
}
?>
Problem
The URL re-writes doesn't seems to be working. When I go to /refer/somerefhash , it says :- Not Found. But, if I use the same refhash and then user the URL refer_handler.php?refhash=thehashhere Then everything seems to be working fine.
How can I fix this ?
Thank you.
The problem is (\\d+)
only allows digits. And base64
encoded string may contain other characters.
Try this:
RewriteRule ^refer/(.+)$ refer_handler.php?refhash=$1 [L,QSA]
This captures 1 or more of any characters instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.