I am trying to write a Rewriterule which takes a domain from a URL of the format
https://www.example.com/sample?TARGET=https%3A%2F%2Fwww.example.com%2Fexample%2Fhelp%3Fparam%3D1.
If the TARGET
parameter is present I need to redirect the user to the value inside the TARGET
query parameter. My rewrite rule is below:
RewriteCond %{QUERY_STRING} TARGET=([-a-zA-Z0-9_+]+)
RewriteRule ^(.*)$ %1? [R=302,L]
This does not work because of two problems:
%1?
in the rewrite rule causes the rewrite to append the value of the TARGET query string to the existing domain.The value of
%1
only containshttps
rather thanhttps%3A%2F%2Fwww.example.com%2Fexample%2Fhelp%3Fparam%3D1
.
I understand that this might not be the best way to go ahead with this, and I am open to suggestions.