apache - mod_rewrite multiple question marks -


occasionally marketing department send out mailer contains links multiple question marks in them.

http://www.acme.com/site-page.jsp?content=mainpage?utm_campaign=somecampaign&utm_source=email 

this results in application server interpreting mainpage?utm_campaign parameter instead of mainpage. there way intercept these erroneous urls in apache , replace second ? &.

you can put code in htaccess (which has in root folder)

rewriteengine on  rewritecond %{query_string} ^(.+?)\?(.+)$ rewriterule ^site-page\.jsp$ /site-page.jsp?%1&%2 [r=302,l] 

this code 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 have params:

  • content = mainpage
  • utm_campaign = somecampaign
  • utm_source = email

note: feel free change 302 (temporary) redirect 301 (permanent) redirect


edit

rewritecond %{query_string} ^(.+?)\?(.+)$ rewriterule ^(.*)$ /$1?%1&%2 [r=302,l] 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -