0

I am trying to redirect every url from a domain to a second "domain" and to keep the url part after the "/".

Here's an example of what I'm trying to do: When someone visits mydomain.com/any-url he should get redirected to urltracker.com/events/redirect_to=http%253A%252F%252Fseconddomain.com%252Fany-url

I'm currently using

RewriteEngine on 
RewriteRule ^(.*)$ http://urltracker.com/events/redirect_to=http%253A%252F%252Fwww.seconddomain.com%252F$1 [R=301,L]

But this code redirects me to urltracker.com/events/redirect_to=http53A52F52Fseconddomain.com52Fany-url

Every "%2" disappears. Can you guys help me change the htaccess so it will not replace %2 ? Thanks!

Edit: What I actually need is to have all special characters after "redirect_to=" double encoded.

2 Answers2

0

You can check : https://stackoverflow.com/a/6529394/1079254

Maybe you will need "AllowEncodedSlashes On" because I think you will have a problem with slash in your 'redirect_to' parameter.

Community
  • 1
  • 1
Calumah
  • 2,865
  • 1
  • 20
  • 30
  • No, it will not work. What I basically need is to have all special characters after "redirect_to=" double encoded. – Flippy Flop Sep 28 '14 at 17:10
  • Try "B" flag for that : https://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_b (only after apache 2.2) – Calumah Sep 28 '14 at 17:24
  • Doesn't change anything, I think "AllowEncodedSlashes" is Off and I do not have access to httpd.conf. – Flippy Flop Sep 28 '14 at 18:04
  • Here a way to do it without editing apache configuration but with php for example... 1) Get url path from request with $_SERVER['REQUEST_URI'] 2) Convert it with base64 and urlencode 3) Use header("Location: http://urltracker.com/events/redirect_to=" . $url_encoded);die(); 4) Update code on urltracker to handle base64 string. – Calumah Sep 29 '14 at 07:38
0

I think I will try to do it in PHP. I managed to keep the characters in double encoded form by using "\", problem is that I want the "any-url" part to have only slashes double encoded, not every special character. Currently, it will double encode every special character, I don't think I can select somehow to only encode slashes.