Jump to content

Force URLs to be written with full protocol (https)


Runar

Recommended Posts

It seems all URLs are written with relative protocol (like this: //example.com/loremipsum), and I believe this is messing with my attempts to use PageSpeed.

Is there any easy way to force all URLs, including those in posts and other content, to be written with the full protocol?

Link to comment
Share on other sites

Apparently this is expected behavior when using a CDN (when a custom domain/path is set in the storage configuration it counts as using a CDN), according to support. They claim it's not possible to force all URLs to include the protocol.

I understand it's not possible to do by clicking a button, but it must be possible by editing the core files (stupid idea, I know). I am willing to take this risk, however, as I need to debug why PageSpeed is behaving strange. Does anyone have any idea where I need to start? I've tried to edit both the Url and File classes (I'll post the exact code later) without it making any difference.

Link to comment
Share on other sites

If you were going to edit source files to do this for debugging purposes, you'd need to edit the Url class as that's where the URLs are generated from. I don't have exact edits for you, but you'd want to force the protocol to something other than PROTOCOL_RELATIVE (probably PROTOCOL_HTTPS) in the various functions that generate a URL.

Link to comment
Share on other sites

Thank you for your reply, @bfarber! Replacing «//» with «https://» on the following two lines seemed to do the trick:

system/File/Amazon.php, line 241:

return preg_replace( '#^http(s)?://#', 'https://', rtrim( ( empty( $this->configuration['custom_url'] ) ) ? static::buildBaseUrl( $this->configuration ) : $this->configuration['custom_url'], '/' ) );

system/Http/Url.php, line 833:

$url = 'https://' . mb_substr( $url, mb_strpos( $url, '://' ) + 3 );

However, it seems there are other causes for my PageSpeed issues, so I’ll most likely revert back to the original lines after I’m done investigating. It was very helpful, though, to be able to force the full protocol in all links and URLs!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...