Viber 双编码网址包含西里尔字母

问题描述 投票:0回答:1

最近客户报告说,当我们在 Viber 上分享链接时,他们无法打开我们的链接,并且仅在 iOS 上。他们被重定向到 404 页面。我开始检查问题所在,我注意到由于某种原因,Viber 仅在 iOS 上对网址进行了双重编码。

发送的示例网址:

 example.com/%D0%BA%D0%BE%D0%BD%D1%82%D0%B0%D0%BA%D1%82%D0%B8/
End url for the user opening it on iOS: example.com/%25D0%25BA%25D0%25BE%25D0%25BD%25D1%2582%25D0%25B0%25D0%25BA%25D1%2582%25D0%25B8/

我注意到所有西里尔字母前面都添加了“25”。我已经在 Whatsapp、Messenger 和 iOS 上共享的链接上进行了测试,运行良好,但问题仅出现在 iOS 版 Viber 上。相同的网址可以在 Android 版 Viber 和桌面版 Viber 上正确打开。 url 的元数据也正确发送给 iOS 上的用户。

所以我最终将其添加到我的functions.php 文件中 - 使用 WooCommerce

add_action('init', 'normalize_request_uri_for_ios');

function normalize_request_uri_for_ios() {
    // Check if the user is on an iOS device
    if (wp_is_mobile() && strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false) {
        // Decode the current URL
        $decoded_uri = urldecode($_SERVER['REQUEST_URI']);

        // Check if the URI contains the query parameter `redirected=1` to prevent loops
        if ($_SERVER['REQUEST_URI'] !== $decoded_uri && strpos($decoded_uri, '%') === false && !isset($_GET['redirected'])) {
            // Append the `redirected=1` parameter to prevent further redirection
            $new_uri = add_query_arg('redirected', '1', $decoded_uri);
            wp_safe_redirect($new_uri, 301);
            exit;
        }
    }
}

它解决了我的问题,但我觉得这对我来说是一个临时解决方案,而且我不确定这是否遵循处理此类问题的最佳实践。我也很确定这以前从来不是问题,因为我们通常会与客户分享很多链接,但从未遇到过这样的问题。

woocommerce urlencode urldecode viber
1个回答
0
投票

我可以确认,我观察到了同样的行为。以前这不是问题。 #anchorLinks 也被破坏,因为它们变成了 /link/%23anchorLinks。

© www.soinside.com 2019 - 2024. All rights reserved.