If i write .php?redirect_to=/?parameter1=dog¶meter2=dog¶meter3=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¶meter2=dog¶meter3=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).
- 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
2 Answers
Reset to default 1I 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¶meter2=dog¶meter3=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 &
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¶meter2=dog¶meter3=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
评论列表(0条)