• Hi,
    we’re using the “AMP for Worpress” Plugin (in paired mode) together with the “Newspaper” Theme. We also have a webshop under example.com, but the WordPress system is installed on a different server and rendered under example.com/blog using a apache proxy_pass directive.

    Everything works well, exept the rel=amphtml Link for the AMP version of each side. Instead of example.com/blog/post1/?amp it shows example.com/post1/?amp .

    Any idea how to handle that or rather were to set the hostname with the “blog” directory?

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Weston Ruter

    (@westonruter)

    The logic for the amphtml link can be seen in the amp_add_amphtml_link() function:

    https://github.com/ampproject/amp-wp/blob/35ca34f75b0e7bfaac9cc937068c05118c55087c/includes/amp-helper-functions.php#L158-L221

    It uses the current $_SERVER['REQUEST_URI'] to determine the AMP URL for a given URL by adding ?amp to it.

    I’m not sure how you have your proxy set up, but it seems to be you need to ensure all URLs are being rewritten in the proxied output.

    I am working with marketing4kuebler. Let me jump in..
    Why don’t you use the home URL?
    The revere proxy is set up in that way, that the request von example.blog/blog ends up on wordpress.example.com/ so that is the request URI the AMP extension is seeing.
    Other wordpress subpages work, because – I guess – they use home URL and so on.

    Maybe a switch could be added to use standard behavior in case the $_SERVER[‘REQUEST_URI’] is needed ? (but of course it would be nice if this can be fixed without a config switch)

    Plugin Author Weston Ruter

    (@westonruter)

    Home URL? I don’t understand.

    The AMP URLs are specific to the non-AMP URLs. This is the “paired AMP” scheme, where a given non-AMP page has a corresponding AMP page.

    So given this page: https://www.kuebler-sport.de/blog/squash-regeln-im-ueberblick/

    The expected AMP page would be located at https://www.kuebler-sport.de/blog/squash-regeln-im-ueberblick/?amp

    Each non-AMP URL would have a different corresponding AMP URL.

    This is the case for the AMP plugin in Reader or Transitional modes, both of which are using this paired AMP scheme.

    In the AMP plugin’s Standard mode, then AMP is canonical and there is no non-AMP version: AMP is used as the framework for the site.

    I just mean, that I does not seem right to use the $_SERVER[“REQUEST_URI”] to determine the current URL.

    Shouldn’t that be done similar to this?

    home_url( $wp->request )

    https://wordpress.stackexchange.com/a/274572/98416

    I think then it would work also with special cases, like proxies.

    Other links work on the blog behind of the proxy. I assume the AMP URL can be generated in a similar way?

    Plugin Author Weston Ruter

    (@westonruter)

    Not really because $wp->request only includes the path, not any arbitrary query vars. In order to map every non-AMP to a corresponding AMP one, the exact same URL should be used with the addition of the amp query param.

    Using REQUEST_URI is common for WordPress. For example, add_query_arg() and remove_query_arg() default to using the REQUEST_URI when no URL is provided.

    The REQUEST_URI is the standard way for PHP to determine the current URL path. As a matter of fact, $wp->request is actually derived from REQUEST_URI.

    So I think you need to make sure that your proxy logic is rewriting this path to have the right value.

    I asked here https://wordpress.stackexchange.com/questions/354375/how-to-run-wordpress-behind-a-reverse-proxy-so-that-extensions-still-can-detect

    actually I have some idea in my mind how we could fix that which I will post there.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘rel=amphtml URL with proxy’ is closed to new replies.