BobB
BobB

Reputation: 762

RewriteRule url to string replace of an &

I need to rewrite a url that has an ampersand as the first char in the querystring. I need to be able to remove it.

So the starting url is:

/shop/partner;jsessionid=7giu21yo7tKsqXAL5Wv8.dwapp01?&code=PARTNERDHTE&partnerBackToUrl=partnersiteurl

The &code is my problem

My rules so far are

RewriteCond %{QUERY_STRING} ^code=(.*)$ [NC]
RewriteRule ^/shop/partner(.*)$ /store/partner/redirect/code/%1? [R=301,L]

This works if I remove the & from in front of &code. I need something that can simply strip out that & from in front of code and then let my rule run.

Upvotes: 1

Views: 46

Answers (1)

anubhava
anubhava

Reputation: 785128

You can tweak your URL to allow & before code:

RewriteCond %{QUERY_STRING} (?:^|&)code=([^&]+) [NC]
RewriteRule ^/?shop/partner(.*)$ /store/partner/redirect/code/%1? [R=301,L]

Upvotes: 1

Related Questions