Occasionally the marketing department would send out a mailer that contains links with multiple question marks in them.
http://www.acme.com/site-page.jsp?content=mainpage?utm_campaign=somecampaign&utm_source=email
This results in the application server interpreting the mainpage?utm_campaign
as the parameter instead of just mainpage
. Is there a way to intercept these erroneous urls in Apache and replace the second ?
with an &
.
You can put this code in your htaccess (which has to be in root folder)
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.+?)\?(.+)$
RewriteRule ^site-page\.jsp$ /site-page.jsp?%1&%2 [R=302,L]
This code will redirect
/site-page.jsp?content=mainpage?utm_campaign=somecampaign&utm_source=email
to
/site-page.jsp?content=mainpage&utm_campaign=somecampaign&utm_source=email
Now you have those params:
content
= mainpage
utm_campaign
= somecampaign
utm_source
= email
Note: feel free to change 302
(temporary) redirect to a 301 (permanent) redirect
EDIT
RewriteCond %{QUERY_STRING} ^(.+?)\?(.+)$
RewriteRule ^(.*)$ /$1?%1&%2 [R=302,L]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With