Skip to content

Instantly share code, notes, and snippets.

@arelthia
Last active June 23, 2017 15:49
Show Gist options
  • Save arelthia/499b749e2cf327f7b34d6b8c49f2c927 to your computer and use it in GitHub Desktop.
Save arelthia/499b749e2cf327f7b34d6b8c49f2c927 to your computer and use it in GitHub Desktop.
Force ssl on one page and force http on specific pages.
add_action( 'template_redirect', 'pintop_ssl_redirect', 1 );
function pintop_ssl_redirect() {
//page that should be ssl
if ( is_page( 1264 ) && ! is_ssl() ) {
if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
wp_redirect(preg_replace('|^http://|', 'https://', $_SERVER['REQUEST_URI']), 301 );
exit();
} else {
wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
} else if ( is_page( array( 'main', 'business-listing' ) ) && is_ssl() && !is_admin() ) {
//pages that must be http
if ( 0 === strpos($_SERVER['REQUEST_URI'], 'http') ) {
wp_redirect(preg_replace('|^https://|', 'http://', $_SERVER['REQUEST_URI']), 301 );
exit();
} else {
wp_redirect('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301 );
exit();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment