Try the template_redirect hook
function portal_protection() {
if ( get_field('enable_portal_protection') && !current_user_can('administrator') ) {
$referring_url = get_field('referring_url');
$redirect_url = get_field('redirect_url');
$referer = $_SERVER['HTTP_REFERER'];
if ( $referer != $referring_url) {
wp_redirect( $redirect_url );
exit;
}
}
}
add_action( 'template_redirect', 'portal_protection' );
Also use wp_redirect. it’s the WordPress way of redirecting.
Related Posts:
- What is the wordpress way of displaying local external content?
- Show different page for first time user
- wp_login_form redirect problem
- adding GET variables to a header() location in a page template
- PHP header(Location: …): Force URL change in address bar
- php refresh current page?
- Host the wp-admin on another domain?
- WordPress localhost site redirect to live site
- My wordpress multisite homepage redirects to signup page
- Login redirect to previous page
- WordPress install enters an infinite loop
- WordPress HTTPS redirect loop
- Using `auth_redirect` : keeps asking me to login even when I’m logged in
- How can I move/redirect single blog posts from one blog to another?
- How do I skip wordpress’s 404 handling?
- Redirecting to home-page when saving any edited code
- Can WordPress redirect to a “similar page” in case of 404 error
- Hacked website redirect, only on desktop, help with restoring it [closed]
- Can I check for maintenance mode before redirecting to subdomain?
- Moving variables from one page to another
- How to create a 301 redirect that doesn’t apply to subsites
- WordPress blocking/preventing viewing of .cgi file in subdirectory [closed]
- Custom Registration page – prevent redirect to wp-login.php?action=register
- https redirect (with .htaccess) redirect loop
- How to auto login after registration? [duplicate]
- homepage redirects to login page when user session expires
- How to redirect user to a specific page based on username?
- Redirect blog archive into certain format
- How to publish new posts/pages in root instead of subfolder, but keep old structure in place?
- forward domain name to particular page?
- Contact Form 7 Data to Whatsapp Link
- Auto-detect the redirect url from the original url
- How can I replace my primary url globally with a parked one?
- I need to redirect an entire subdirectory in WordPress to the homepage – is this correct?
- My website on checking showing 403 error on HTTP Status [closed]
- I get redirected too many times only in wp-admin?
- Redirecting Pages That No Longer Exist — But Could in the Future
- How do I determine what is causing a redirect for a given page?
- Trouble running local WordPress in Google App Engine
- Empty folder being created by WordPress, breaks site
- About to migrate site to new domain
- Redirect all users to dashboard unless custom post type
- Redirecting connection from IP to localhost
- WordPress directing to Posts page (edit.php) instead of saving post
- HTML Redirect to WP pages
- Changing theme = change home page for mobile visitors?
- Redirect User on Login based on role WP 3 – Multi-Site
- production site routes to staging site after cloning
- Redirect old URL (with different post ID) to new URL
- How to redirect an old page url to the homepage
- Create short URL with auto 301 redirect
- Custom URL routes
- Delete Redirect Slug For Specific Post
- Duplicated WP site manually, now links redirect wrong [closed]
- redirecting an entire WP site from one top level domain to another
- Load function with login_redirect
- Missing domain http://./wp-… in redirects
- All URLs Redirect to Main Page
- Why I am not able to direct user to my blog section without login?
- Force User Login
- Import RSS as posts with redirect?
- Parked domain redirecting to wrong error404 page
- Subdomain redirect problem
- redirect from old URL structure
- ACF get_sub_field ALT TAG in the repeater doesn’t show
- How to Redirect WordPress domain.com/?anyword to 404 Page?
- How can I prevent caching of wp_redirect?
- Redirect Category Media ‘URL’ when clicked
- Error in /blog redirection – ubuntu default WP installation
- wordpress automatic URL ‘page’ parameter rewrite
- Changing post depending upon where you’re redirected from?
- 302 redirect *.at/site redirecting to .comsite
- Loading /wp-content/uploads/site as /site/
- How to redirect user to the specific URL and display notice
- Redirect after plugin activation
- Redirect affecting development folder
- change home_url and site_url but don’t redirect to home_url and site_url on load
- How do I skip wordpress’s 404 handling?
- All devices on my network redirect me to an old domain
- WordPress multisite and redirect to subpage
- My WordPress site redirects to port 8082
- wp-login.php redirect problem
- Custom, conditional redirect on logout
- International characters in slugs to redirect to
- How to Block WordPress from subdomain?
- login page not working [closed]
- Debugging a redirect loop affecting only certain pages
- WordPress redirect to splash page once a day for the first week
- Modifying and Displaying URL’s in a Post Template using parse_url
- after logout, get_current_user_id still holds value
- noheader on the user/frontend side
- Solution for WordPress URL structure changes and 301 redirects?
- WordPress redirect from one directory to another but exclude wp-admin and wp-login.php
- How can I redirect foreigners by IP to other URL in WordPress?
- How to change Ugly link?
- WordPress site redirecting to developers URL
- How to use the HTTP API (wp_remote_get) instead of cURL?
- How to Create Custom Route to a page in WordPress
- How to create a redirect to another domain like safe redirect manager from php
- Post Migration Site Migration Redirects All Known Solutions Attempted