• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Force https for specific pages

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › Force https for specific pages

This topic is: not resolved

Tagged: https://

  • This topic has 3 replies, 2 voices, and was last updated 10 years, 7 months ago by David Chu.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • November 8, 2014 at 3:57 am #130883
    stl99
    Member

    Hi,

    This happens with the default WP theme and no plugins activated as well, after multiple WP consultants provided me with broken solutions or offered to set up outdated plugins for me, I'd like to try to ask here:

    Basically I need to force https on specific pages while all other pages should still/only use http (https to http redirect).

    The problem is that functions like this

    //Force single page SSL

    add_action( 'template_redirect', 'fb_ssl_template_redirect', 1 );
    function fb_ssl_template_redirect() {

    if ( ( is_page(752) || is_page(17686) || is_page(19587) ) && !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_ssl() && !is_admin() ) {

    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();
    }
    }
    }

    result in a redirect loop for the included pages.

    Any ideas? I'm more than willing to pay for a solution, it just needs to work reliably and don't rely on plugins.

    Cheers,
    Thomas

    November 10, 2014 at 1:22 pm #131095
    David Chu
    Participant

    Hi,
    When I do HTTPS for targeted pages, I don't use plugins, I do it at the server level instead.

    That's not to say that it's impossible to do it via PHP, but I just don't. Doing it outside of WP is simpler.

    As you've seen, this is fairly breakable. Even doing it the way I do, if someone fools around with the URL by changing the permalink and/or the page title, that will also break, because the code cannot psychically know what the URL is. ๐Ÿ™‚

    If multiple developers are not getting it done, you may have other difficulties. For instance, I don't do such changes on Windows servers, only on flavors of UNIX (which is much more common anyway). Also, if your host has some weird server setup that can't be altered by a developer, that could also prevent this from working, my method or the above method.

    Hope that gives some ideas.

    Dave


    Dave Chu ยท Custom WordPress Developer – likes collaborating with Designers

    November 10, 2014 at 2:30 pm #131103
    stl99
    Member

    Hi Dave,

    Thanks a lot for your reply, fortunately there was one developer who could do it after all ๐Ÿ˜‰

    Cheers,
    Thomas

    November 10, 2014 at 2:39 pm #131104
    David Chu
    Participant

    Cool!
    That's not a tough fix for a decent coder. ๐Ÿ™‚

    Dave


    Dave Chu ยท Custom WordPress Developer – likes collaborating with Designers

  • Author
    Posts
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2025 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble