Reputation: 35
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
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
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