• I have the following script in header.php with the intent of creating a hreflang tag:

    <link rel="alternate" href="https://domain.com<?php echo parse_url($_SERVER['REQUEST_URI'],PHP_URL_PATH); ?>" hreflang="x-default" />

    The idea is to return something like this:

    <link rel="alternate" href="https://domain.com/URL/Path" hreflang="x-default" />

    But what I get is:

    <link rel="alternate" href="//domain.com/URL/Path" hreflang="x'-default" />

    As you can see, the “https:” part has been left out but I need it for the hreflang tag. Any suggestions as to what’s happening?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Since the https:// part is hard-coded, something else seems to be at work here. Just for testing purposes, have you tried your code with something other than https just to see if that something else also gets removed? I’m wondering if there’s something that is specifically looking for https.

    Thread Starter swahlgren

    (@swahlgren)

    Hi Marios and thanks for the response!

    I tried it out with ftp and http. Http is also removed but not ftp.

    Is your site running on https? Do you use any plugins to help force URLs to be https?

    The reason I ask is that // is sometimes used in place of http and https to mean use whatever is currently being used. This helps avoid some errors. I’ve seen it and used it when specifying the src for JavaScript files, but I haven’t seen it used to specify an href. I’m wondering if there’s a plugin that’s converting the the http and https to // as a way to “help” you.

    Thread Starter swahlgren

    (@swahlgren)

    Just as you suggested a plugin is “helping” me by rewriting the protocol. I use https via Cloudflare and that means I can’t turn it off without asking for mixed content trouble.

    https://support.cloudflare.com/hc/en-us/articles/203652674

    Any way to solve this?

    That certainly explains what’s going on. Given how many users CloudFlare has, I wonder if what they’re doing is perfectly fine. They indicate in their document that they specifically target link tags so the behaviour is expected.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Protocol is stripped by PHP’ is closed to new replies.