I have a redirection problem on WordPress, I want to show a different page to users that come from search engines instead of those who come directly
Have the "Insert PHP Code Snippet" plugin for this purpose.
The script is :
<?php
##Begin of conditions
##End of conditions
## If conditions Met above
If(isUserValid() === "true") {
header("Location: https://example.com"); } #external URL
## If conditions Not Met above
else
{
header("Location: https://example.net/post"); } #wordpress post
So the problem here, the PHP code is inserted in that post https://example.net/post If the conditions are okay, the redirection goes smooth
But when the conditions aren't met, I'm getting a redirection loop and error.
Because the header is the same where I've put the code.
Is there a way to write a code that can disable the PHP code after the first redirection?
For SEO I need the redirection to be done to the same post, to avoid losing ranking.
EDIT: I need to replace this line
header("Location: https://example.net/post"); } #wordpress post
With another line, that will let you stay on the same page if conditions aren't met. That will fix my issue.
Thank you