Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mod_rewrite multiple question marks

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 &.

like image 305
radimpe Avatar asked Sep 19 '14 15:09

radimpe


1 Answers

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]
like image 146
Justin Iurman Avatar answered Nov 15 '22 10:11

Justin Iurman