thodison
thodison

Reputation: 35

htaccess redirect query string, but encoded ? to &

I want to redirect

https://www.aaa.com/query?v=abc123_ABC

to: https://bbb.com/?url=https://www.aaa.com/query?v=abc123_ABC

I use this in .htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ https://bbb.com/?url=https://www.aaa.com/$1  [L,B,NE,NC,QSA,R=301]
</IfModule>

But the output is: https://bbb.com/?url=https://www.aaa.com/query&v=abc123_ABC

The ? was converted into &, what's wrong with the code? Thanks.

==== You can test it here: https://htaccess.madewithlove.be/

Upvotes: 2

Views: 132

Answers (2)

RavinderSingh13
RavinderSingh13

Reputation: 133508

As per OP's request and shown samples could you please try following.

RewriteEngine ON
RewriteCond %{THE_REQUEST} \s(/query)\?(v=abc123_ABC)\s [NC]
RewriteRule ^(.*)$ https://bbb.com/?url=https://%{HTTP_HOST}%1?%2 [NE,L]

Upvotes: 3

Amit Verma
Amit Verma

Reputation: 41219

The following rule should work.

RewriteEngine on

RewriteCond %{THE_REQUEST} /query\?v=.+\s [NC]
RewriteRule ^ https://bbb.com/?url=%{REQUEST_SCHEME}://%{HTTP_HOST}%{REQUEST_URI}?%{QUERY_STRING}  [L,R]

Upvotes: 2

Related Questions