I have a tricky rewrite situation where I am needing to rewrite old URL’s that have parameters, to new URL’s, but at the same time appending the parameters of the old (now invalid) URL to this new URL.
Example: An old link of ring-details.php?product=MQ==&hash=376FGE367ER872CBD5 will now become rings/ring-detail/23.htm where the number 23 is actually the base64_decoded value of the product URL above.
So essentially I need to do this:
-
Check if the page being requested is ring-details.php and that there
is a parameter ‘product’ present. Hash is no longer used. -
Take the product parameters value (MQ==), base64_decode it
-
Append the decoded value to the new URL: rings/ring-detail/$1.htm
where $1 is the decoded product URL parameter.
I am not asking to be spoon fed, but any hints or good resources would be great. Thanks,
As far as I know, you cannot decode Base64 in .htaccess/mod_rewrite. But you could make a workaround via PHP.
So you have to catch the old URL and rewrite it to the PHP file, which decodes Base64 and redirects to the new URL.
Content of
.htaccess:Content of
redirect.php:But actually you could modify
ring-details.phpinstead and add this code at the very top: