I am building a website for my company which loads over HTTP inside the company and over HTTPS outside company's network. This is a compulsion and there is no way we can avoid it. The site needs to work over both HTTP and HTTPS.

This mixed HTTP & HTTPS is giving a huge problem to us. I tried using plugins which make the URLs relative. But some URLs are still absolute and the admin panel doesn't open properly over HTTPS.

Is there any hack using which we can remove HTTP from the site URL and have just two slashes (//) in it? This will solve our problem, at least for front end.

Thanks in advance. Your help is appreciated.

  • 1
    The obvious answer is to go full https, it really doesn't make any sense to have less security in the company network where the biggest security threat is. Jul 14, 2016 at 19:10

1 Answer 1


To remove http: and https: from all links, use the following script:

add_action( 'plugins_loaded', 'wpse_232287_init' );

function wpse_232287_init() { // Initiate the function
    ob_start( 'wpse_232287_remove_http' );

function wpse_232287_remove_http( $buffer ) {
    // Check for a Content-Type header, only apply rewriting to "text/html" or undefined
    $headers = headers_list();
    $content_type = null;

    foreach ( $headers as $header ) {
        if (strpos( strtolower( $header ), 'content-type:' ) === 0 ) {
            $pieces = explode( ':', strtolower( $header ) );
            $content_type = trim( $pieces[1] );

    if ( is_null( $content_type ) || substr( $content_type, 0, 9 ) === 'text/html' ) { // Replace 'href'/'src' attributes within script/link/base/img tags with '//'
        $return = preg_replace( "/(<(script|link|base|img|form)([^>]*)(href|src|action)=[\"'])https?:\\/\\//i", "$1//", $buffer );
        if ( $return ) { // On regex error, skip overwriting content
            $buffer = $return;
    return $buffer;

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.