What’s happening is you’re sending an unauthenticated visitor to a certain page. The code in that page also picks up that the user is unauthenticated, and sends them to the page that they’re already on. Because the page keeps on sending the visitor to the same page, the visitor can’t go anywhere. This is called a redirect loop.
You’re on the right track with the $_SERVER['REQUEST_URI']
check. However, paths like ../
and .../
won’t work. You need to use the actual URL of the page that you’re redirecting to (sans the domain and protocol). Essentially, you need to use this code:
if ( trim( $_SERVER['REQUEST_URI'], "https://wordpress.stackexchange.com/" ) != 'landingpage' && ! is_user_logged_in() ) {
wp_redirect( home_url( 'landingpage' ), 301 );
exit;
}
Related Posts:
- How are both HTTP and HTTPS versions displaying?
- Redirect Loop to Page, Can’t Find Origin, Can’t Remove [closed]
- Can’t access login screen, wp-login.php 404’s
- Infinite Redirect Loop after moving to subdirectory
- Moving wordpress to different url/server creates redirect loop
- Infinite Loop after Genesis Theme Upgrade
- Unable to login + Redirect loop on mobile
- This webpage has a redirect loop issue with SSL page
- How to display Yoast SEO meta description in archive template for each post instead of the_excerpt()? [closed]
- How to get Author ID outside the loop
- remove tags from the_content
- Why do themes rely on “The Loop”?
- How to place comments_template(); outside the loop?
- Endless loop with wp_insert_post and wp_update_post
- Hook into the loop via a plugin, and output something after every X post?
- Two custom loops, pagination, offset
- Access to Media Library
- next_posts_link not working in custom loop
- How to sort posts in archive loop
- wordpress loop and template files
- How to iterate through database until it find a match
- Show top level comments ordered by number of replies
- Creating nested forum loops in bbPress [closed]
- Adding active/current class to get_terms list
- wordpress change the loop order by dynamic value
- Post Format single-loop.php using get_template_part
- Display posts from multiple user roles
- Display content of page template (get_page)
- A loop with all articles with certain text strings in tags
- Prevent Headers from being sent
- How do I get row padding in a post feed?
- How can I create a legend (Key) like the one in the footer on WordPress StackExchange
- It is possible to encounter horrible bugs if I place a main loop that uses `query_posts` right above the main bbPress loop?
- Including post thumbnail url in loop’s post object to reduce number of queries
- How to show “teaser” posts on blog / archive pages, otherwise full posts
- Make blog page show 10 on first page, 9 on every other page
- Duplicate posts in paginated results
- Alter query using pre_get_posts() if meta_key is present
- Next Posts Prev Posts for Standard post format only
- Two loops on different pages do the same thing, but only one page works
- Posts active and expired in different loops
- Genesis multiple category custom loop 404s after first page
- Shortcode in posts called by ajax is not working
- Using Javascript for Looped Content
- Making a query to the DB using same parameters of loop
- Variable not being passed into WordPress loop
- Exclude duplicated $sticky post from combined loop content
- Getting a custom field in the middle of a loop
- Pagination on Single Post
- Display Posts Only with Specific Tag
- How to get my loop to paginate?
- Get author Meta for particular user inside the loop
- WP Loop. If featured image is a panorama (3:1 ratio) execute some code
- Trying to get property of non-object in shortocde
- Foreach displays from last to first
- value of metadata is null wrong use of if statement
- Count post views in loop
- How to Loop with the final result formatted differently?
- Tags on page (not post) returns nothing – why? Improved clarified question!
- Separate First Post Loop
- add offset to archive page
- Category ID returns as ‘0’?
- make get_post work in the loop
- How to display 3 post per slide
- Show terms in archive page
- For Each +1 WordPress Loop
- Loops for cat links not looping for wordpress site
- Skip 5 latest post while paging?
- WordPress: query pages except remove one page
- get_post_meta printing empty fields, but it shouldn’t be
- Sort posts according to a numeric value entered with ACF
- Is it possible to set archive.php instead of index.php to display blog?
- How to read taxonomy in loop?
- wp_get_attachment_url not fetching URL?
- get the value for ALT is we check to see if an actual ALT value is set, if not we use the caption and if no caption is set we use the title
- how to add 4 post in one carousel slide
- How to get all multi-select user meta values and add them to an array?
- How to resolve a reload loop issue in the frontend when logged in to WordPress multi-site backend admin area
- Exclude Posts Using Meta Query and User Meta
- Is “the loop” a template tag?
- Excerpt isn’t working or am I missing something?
- Can I temporarily disable global $post?
- Shortcode for pulling specific Post Title outside loop when ID is passed in
- Show a list of user posts in the user admin page
- WordPress with woocommerce custom query
- Page gets displayed in post field
- Active class for my flexslider in WordPress
- WordPress loop only displays 5 articles max?
- get_template_part() to render single page Theme
- Can’t see custom field after the Loop [closed]
- Showing related posts (custom post type) outside of the loop
- Same Loop on Multiple Pages
- Paged homepage – requirements?
- Least Number of Loops to Create Custom Homepage?
- The Loop for my theme with static front page is not working
- WordPress loop: Display if posts exist
- strange parse error when including a loop template within another template
- Previous Posts Link and Next Posts Link Show All The Same Articles?
- Showing ads after posts in home page
- Prevent duplicating specific column from database table