.htaccess - mod_rewrite old urls with parameters to new URL's, but using the old parameters with the new URL -


i have tricky rewrite situation needing rewrite old url's have parameters, new url's, @ same time appending parameters of old (now invalid) url new url.

example: old link of ring-details.php?product=mq==&hash=376fge367er872cbd5 become rings/ring-detail/23.htm number 23 base64_decoded value of product url above.

so need this:

  • check if page being requested ring-details.php , there parameter 'product' present. hash no longer used.

  • take product parameters value (mq==), base64_decode it

  • append decoded value new url: rings/ring-detail/$1.htm $1 decoded product url parameter.

i not asking spoon fed, hints or resources great. thanks,

as far know, cannot decode base64 in .htaccess/mod_rewrite. make workaround via php.

so have catch old url , rewrite php file, decodes base64 , redirects new url.

content of .htaccess:

rewriteengine on rewritecond %{query_string} ^product=([^&]+) rewriterule ring-details\.php$ redirect.php?product=%1 [l] 

content of redirect.php:

<?php header('location: http://'.$_server['http_host'].'/rings/ring-detail/'.intval(base64_decode($_get['product'])).'.htm', true, 301); ?> 

but modify ring-details.php instead , add code @ top:

<?php if(!empty($_get['product'])){     header('location: http://'.$_server['http_host'].'/rings/ring-detail/'.intval(base64_decode($_get['product'])).'.htm', true, 301);     exit; } ?> 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -