2

If i write http://domain.com/wp-login.php?redirect_to=http://domain.com/specificpage/?parameter1=dog&parameter2=dog&parameter3=cat in the url address bar (to make the login page redirect to a specific page with parameters) and login.

I get redirected to the right page but only with first parameter (http://domain.com/specificpage/?parameter1=dog). the other two parameters are stripped from the url.

How can i solve that?

Btw - the parameters are acceptable on this site (set in the functions file with add_custom_query_vars so that's not the problem).

2
  • did you use some security plugin that limits URL length?
    – Pat_Morita
    Jan 10, 2018 at 23:09
  • No. also if i type the url it self (the one that is set in the redirect_to) it's working fine without stripping the parameters.
    – Nori
    Jan 11, 2018 at 8:51

2 Answers 2

1

I think you should encode the & to avoid potential conflicts:

http://domain.com/wp-login.php?redirect_to=http://domain.com/specificpage/?parameter1=dog&parameter2=dog&parameter3=cat
1
  • You should be using percent encoding, not HTML entities. See my answer.
    – Flimm
    May 29, 2019 at 13:00
1

Option 1: Using wp_login_url($redirect):

wp_login_url takes an argument $redirect that will correctly generate the redirect_to query parameter correctly encoded:

echo '<a href="' . esc_attr( wp_login_url( "http://domain.com/specificpage/?parameter1=dog&parameter2=dog&parameter3=cat" ) ) . '">test</a>';

This would print:

<a href="http://example.com/wp-login.php?redirect_to=http%3A%2F%2Fdomain.com%2Fspecificpage%2F%3Fparameter1%3Ddog%26parameter2%3Ddog%26parameter3%3Dcat">test</a>

As you can, special characters like ? and & get encoded using percent encoding to %3F and %26 respectively (not an HTML entity like &amp; as another answer suggested).

Option 2: Using http_build_query:

If you didn't want to use wp_login_url but a more a general tool that applies to search queries in general, you can use PHP's http_build_query instead, like this:

echo '<a href="http://example.com/wp-login.php?' . esc_attr( http_build_query(['redirect_to' => 'http://domain.com/specificpage/?parameter1=dog&parameter2=dog&parameter3=cat']) ) . '">test</a>';

This would print:

<a href="http://example.com/wp-login.php?redirect_to=http%3A%2F%2Fdomain.com%2Fspecificpage%2F%3Fparameter1%3Ddog%26parameter2%3Ddog%26parameter3%3Dcat">test</a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.