0

I have one WordPress page that only contains a shortcode for a slider and is used by other websites as an iFrame.

I need to force SSL one this one single page, but whatever I try, it is not being redirected.

I have tried to achieve it through a following function:

function yst_ssl_template_redirect() {

        $page_id = 498;


        if ( is_page( $page_id )  && ! 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();
            }
        } 
        if ( !is_page( $page_id )  && 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();
            }
        }


    }

However, it always ends up in infinite redirect loop and does not get the work done.

I thought about a solution for forcing SSL through .htaccess, but I could not get it working for one single page.

Any help or guidance is much appreciated and if there is any additional information that I could provide - just tell me.

2
  • While this doesn't answer your original question, I'm sure there is a better way to accomplish what you are doing w/o the iframe, which is causing the problem. If you post some detail on that aspect you will probably see some useful input on making this work.
    – jdm2112
    Nov 16, 2015 at 16:13
  • I have updated the question with info that the page with the slider shortcode is used as an iFrame in other websites.
    – WpDoe
    Nov 17, 2015 at 12:19

1 Answer 1

0

You are getting redirected because of the automatic redirection to the canonical address of the page which is http://.... You will need to use the redirect_canonical filter https://developer.wordpress.org/reference/hooks/redirect_canonical/ to tell wordpress to not redirect for that page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.