skip to Main Content

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/

2

Answers


  1. 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]
    
    Login or Signup to reply.
  2. 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]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search