Hi
Unfortunately or fortunately ??, I found no such issue with redirect_to parameter on my end. It is working fine with LoginPress installed.
For example, I used /wp-login.php?redirect_to=hello-world
. After logging in, I was redirected to the Hello World post. Let me explain to you how the redirect_to parameter works in WordPress.
WordPress enforces strict validation rules for security reasons, which can affect how the redirect_to
parameter behaves based on the URL format.
Relative vs Absolute URLs in redirect_to
If you use a relative URL like /hello-world
in the redirect_to
parameter, WordPress appends this to the site’s base URL (as configured in Settings → General). For example:
- Login URL:
/wp-login.php?redirect_to=/hello-world
After login, WordPress will redirect to:
https://your-site.com/hello-world
If you use an absolute URL, such as https://your-site.com/hello-world
, WordPress validates the domain, protocol, and structure of the URL. WordPress redirects the user to the WordPress admin dashboard if the absolute URL doesn’t match the site’s domain or fails validation.
Example with Encoded URL
If your login URL looks like this:
https://your-site.com/wp-login.php?redirect_to=https%3A%2F%2Fyour-site.com%2Fhello-world
Here’s what happens:
- The
redirect_to
parameter is URL-encoded and specifies the absolute URL: https://your-site.com/hello-world/
.
- WordPress decodes and validates the
redirect_to
URL. Since the domain and protocol match the WordPress site settings, the URL is considered safe.
- After a successful login, the user is redirected to the specified URL.
This format works because:
- The
redirect_to
URL matches the site’s domain and protocol exactly.
- It is properly URL-encoded (e.g.,
:
becomes %3A
, /
becomes %2F
).
Therefore, if your redirection is not working properly, it might be due to a mismatch in domain or protocol or improper encoding. I hope this information was helpful! ??
If you are still facing any issues, please contact us on our support forum so we can help you fix the problem on your site.