• Having issues with missing a slash.

    This is being printed in the amphtml link — but also starting to show errors in Google Search Console.

    The format of the amphtml link is as such:

    https://www.siturl.comblog/category/post-title/?amp

    Notice how .com and blog are NOT separated by a ‘/’ ???

    None of the solutions I’ve found via searching are working. Please help.

Viewing 9 replies - 16 through 24 (of 24 total)
  • Thread Starter johnbenedict

    (@johnbenedict)

    After talking to our dev — we’re doing a good amount of customization > output buffering + link re-writing for our CDN. I probably should have discussed this with him first. So not sure it’d be all that helpful.

    Plugin Author Weston Ruter

    (@westonruter)

    It would still be helpful to know how you are manipulating the home_url so that I can replicate it in the test.

    Thread Starter johnbenedict

    (@johnbenedict)

    Hey @westonruter — after going over this with our developer — we’re not doing anything to home_url. No filter, manipulation, etc.

    In order to fix the issue we were having — we made a simple update to amp_get_current_url():

    This:
    $url = preg_replace( ‘#(^https?://[^/]+)/.*#‘, ‘$1’, home_url( ‘/’ ) );

    To this:
    $url = rtrim(preg_replace( ‘#(^https?://[^/]+)/.*#‘, ‘$1’, home_url( ‘/’ ) ), ‘/’) . ‘/’;

    But to keep from breaking the plugin — we actually went this route in footer.php:

    $html = ob_get_clean();
    $html = preg_replace("!(domain\.com)([a-z0-9])!i", '\1/\2', $html);
    echo $html;

    I hope this helps. Thank you for being so responsive and willing to help.

    • This reply was modified 4 years, 5 months ago by johnbenedict.
    Plugin Author Weston Ruter

    (@westonruter)

    I’m confused as to why home_url( '/' ) on your site would have returned an unslashed home URL without using the home_url filter.

    Thread Starter johnbenedict

    (@johnbenedict)

    I have no idea. I cannot find anywhere in our codebase where this is changed.

    We are however using home_url() quite a bit — and we are always adding that trailing slash — so something like this: home_url( "/something/")

    I did just test the output of home_url( '/' ) — and the trailing slash IS there. So it should be working in your function…

    Plugin Author Weston Ruter

    (@westonruter)

    @johnbenedict Are you doing any rewriting of $_SERVER['REQUEST_URI']?

    I am able to reproduce the issue with the following:

    $_SERVER['REQUEST_URI'] = 'blog/';
    echo amp_get_current_url();

    The function is assuming that $_SERVER['REQUEST_URI'] always starts with a / (as it always does in my experience). But my assumption may be invalid.

    Plugin Author Weston Ruter

    (@westonruter)

    If this is the case, I also have an alternative more robust implementation amp_get_current_url() which I’d appreciate if you’d test: https://github.com/ampproject/amp-wp/pull/4807

    Thread Starter johnbenedict

    (@johnbenedict)

    Hi @westonruter — finally able to look into this for you. No we are not doing any rewriting of $_SERVER['REQUEST_URI']

    Plugin Author Weston Ruter

    (@westonruter)

    OK, well, I’m at a loss.

    In any case, we’ve merged the pull request to make amp_get_current_url() more robust.

    I’d greatly appreciate it if you could patch your amp-helper-functions.php to replace the amp_get_current_url() function with what you can see here:

    https://github.com/ampproject/amp-wp/blob/4743ae5881f05faf518c525005e3409137637b35/includes/amp-helper-functions.php#L386-L416

    With that in place, please remove the workaround you implemented via output buffering and let me know if the issue is resolved.

Viewing 9 replies - 16 through 24 (of 24 total)
  • The topic ‘amphtml missing a slash after site url’ is closed to new replies.