1

I'm working on one of a client site, some weird reason, a lot of their link show like this: https://http://yourdomain.com/xxxx

It's fine to click the link when I use the console to see the source and will redirect to https://yourdomain.com but when it's front page(without console open), click the button(link), will open https//yourdomain.com, will be missing ":" or "//"

I tried to find where those content come from, but no luck, I can't not use DB to remove that old "HTTP", because everytime they create new resource will still have https://http://

So I wonder can I use a .htaccess file to detect all those "https://http://" links to direct "https://" only.

Thanks for the help!

madebymt
  • 377
  • 1
  • 4
  • 27

1 Answers1

0

I don't think it is practical in .htaccess. However, as a temporary solution until you solve the cause of the problem, you should be able to add code to replace bad links at the point WordPress finally "outputs" the page.

I was going to pen a solution but found I only had to modify code for "final output" already here on stackexchange (itself based on this article )

Try adding the following to your theme's functions.php, or for permanence to your own custom site specific plugin.

function my_linkfix_callback($buffer) {      
    $buffer = str_replace( 'https://http://' , 'https://' ,$buffer);
    return $buffer; 
}

function my_linkfix_buffer_start() { ob_start("my_linkfix_callback"); } 
function my_linkfix_buffer_end() { ob_end_flush(); }

add_action('after_setup_theme', 'my_linkfix_buffer_start');
add_action('shutdown', 'my_linkfix_buffer_end');

Obviously this is just a temporary solution until you solve the cause of the problem

scytale
  • 1,339
  • 1
  • 11
  • 14
  • Thank you so much @scytale, I will try to see if that works. – madebymt Oct 04 '18 at 02:01
  • Note when viewed from an "HTTPS" url BOTH `//http://` AND `https://http://` will generate `https://http://` links in a browser. So view the HTML source in your browser and if your ahref links are "//http://" you will need to modify the str_replace in above code. – scytale Oct 04 '18 at 07:43