Wp Login redirect strips parameters from url

If i write .php?redirect_to=?parameter1=dog&parameter2=dog&parameter3=cat in the url address bar (to make the l

If i write .php?redirect_to=/?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 (/?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).

If i write http://domain/wp-login.php?redirect_to=http://domain/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/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).

Share Improve this question edited Jan 10, 2018 at 10:38 Nori asked Jan 10, 2018 at 10:26 NoriNori 351 silver badge5 bronze badges 2
  • did you use some security plugin that limits URL length? – Pat_Morita Commented 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 Commented Jan 11, 2018 at 8:51
Add a comment  | 

2 Answers 2

Reset to default 1

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

http://domain/wp-login.php?redirect_to=http://domain/specificpage/?parameter1=dog&parameter2=dog&parameter3=cat

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/specificpage/?parameter1=dog&parameter2=dog&parameter3=cat" ) ) . '">test</a>';

This would print:

<a href="http://example/wp-login.php?redirect_to=http%3A%2F%2Fdomain%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/wp-login.php?' . esc_attr( http_build_query(['redirect_to' => 'http://domain/specificpage/?parameter1=dog&parameter2=dog&parameter3=cat']) ) . '">test</a>';

This would print:

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745453856a4628394.html

相关推荐

  • Wp Login redirect strips parameters from url

    If i write .php?redirect_to=?parameter1=dog&parameter2=dog&parameter3=cat in the url address bar (to make the l

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信