Title: Redirect loop
Last modified: October 5, 2016

---

# Redirect loop

 *  Resolved [Chet](https://wordpress.org/support/users/chethardin/)
 * (@chethardin)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/redirect-loop-83/)
 * Hey –
 * I am using this function, and I am receiving a redirect loop. Any ideas?
 *     ```
       function country_geo_redirect() {
       $country = getenv('HTTP_GEOIP_REGION');
       if ( ( $country == "MO" ) && ! is_user_logged_in() ) {
       	wp_redirect( home_url( '/missouri-page' ) ), 301 );
       exit;
       } 
       }
       add_action('init', 'country_geo_redirect' );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Contributor [Taylor McCaslin](https://wordpress.org/support/users/taylor4484/)
 * (@taylor4484)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/redirect-loop-83/#post-8259693)
 * Howdy Chet,
 * You have to make sure you don’t just keep redirecting once you get to the desired
   page, something like this should work:
 *     ```
       function country_geo_redirect() {
       	$region = getenv("HTTP_GEOIP_REGION");
       	if ( '/missouri-page' != str_replace( home_url(), '', get_permalink() ) || ( 'MO' != $region ) || is_user_logged_in() ) {
       		return;
       	}
       	wp_redirect( home_url( "/missouri-page/" ) ), 301 );
       	exit;
       }
       add_action("init", "country_geo_redirect" );
       ```
   
 *  Thread Starter [Chet](https://wordpress.org/support/users/chethardin/)
 * (@chethardin)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/redirect-loop-83/#post-8259804)
 * Hey Taylor –
 * Thanks! Can I ask a quick follow-up?
 * I am redirecting people in Missouri to a sub-site on a multisite installation.
   I also want to not redirect them for one page. Would this work?
 *     ```
       function region_geo_redirect() {
       	$region = getenv("HTTP_GEOIP_REGION");
       	if ( '/sub-site-url' != str_replace( home_url(), '', get_permalink() ) || '/page-on-main-site' != str_replace( home_url(), '', get_permalink() ) || ( 'MO' != $region ) || is_user_logged_in() ) {
       		return;
       	}
       	wp_redirect( home_url( "/sub-site-url" ) ), 301 );
       	exit;
       }
       add_action("init", "region_geo_redirect" );
       ```
   
 *  Plugin Contributor [Taylor McCaslin](https://wordpress.org/support/users/taylor4484/)
 * (@taylor4484)
 * [9 years, 8 months ago](https://wordpress.org/support/topic/redirect-loop-83/#post-8260475)
 * Yep that looks about right. We are contemplating how to build in a helper function
   in future releases to make this kind of redirect easier to setup.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Redirect loop’ is closed to new replies.

 * ![](https://ps.w.org/wpengine-geoip/assets/icon-256x256.png?rev=1101492)
 * [WP Engine GeoTarget](https://wordpress.org/plugins/wpengine-geoip/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wpengine-geoip/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wpengine-geoip/)
 * [Active Topics](https://wordpress.org/support/plugin/wpengine-geoip/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wpengine-geoip/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wpengine-geoip/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Taylor McCaslin](https://wordpress.org/support/users/taylor4484/)
 * Last activity: [9 years, 8 months ago](https://wordpress.org/support/topic/redirect-loop-83/#post-8260475)
 * Status: resolved