• You changed the permalink structure without permission, causing all my translated pages to end with “.html” to “-html/”.

    You’ve made a huge difference in my link structure!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter xu wu

    (@wuxu)

    In version 2.8.2, I used the following code to convert all the URLs ending in html normally, but after updating to 2.8.7…
    .html changed to -html

    Original link: https://www.test.com/test.html
    Translated link: https://www.test.com/en/test-html


    With the following code, my sitemap shows the correct URL and the translated URL on all pages of the site, but when I click on it, it will jump from .html 301 to -html.

    add_filter( 'trp_get_url_for_language', 'trpc_remove_end_slash', 10, 6);
    function trpc_remove_end_slash($new_url, $url, $language, $abs_home, $lang_from_url_string, $lang_url_slug){

    if (strpos($new_url, '.html') !== false || strpos($new_url, 'sitemap.xml') !== false){
    return untrailingslashit($new_url);
    }
    return $new_url;

    }

    If I don’t use the code above, I’ll see a .html/ ending in my sitemap. After clicking, it will still 301 jump to the end of -html.

    I’ve tried turning on the fix option for using older versions in 2.8.7 and downgrading to 2.8.2, but all my translated links are with the above issue. Please help provide me with a useful function, thank you very much!

    Plugin Support Anca

    (@ancavictoria)

    Hello,

    If you reverted to 2.8.2 and still have this same issue, it’s possible the issue comes from somewhere else.

    Try and do a compatibility issue or run the filter with a higher priority like: add_filter( ‘trp_get_url_for_language’, ‘trpc_remove_end_slash’, 100, 6);

    Kind regards,

    Anca

    Thread Starter xu wu

    (@wuxu)

    I added the following code to fix it, hopefully it can be of help to anyone experiencing the same problem.

    add_action('template_redirect', 'redirect_html_suffix',999);

    function redirect_html_suffix() {
    // URL
    $request_uri = $_SERVER['REQUEST_URI'];

    if (preg_match('/(.*?)-html$/', $request_uri, $matches)) {
    $new_url = rtrim($matches[1], '/') . '.html';
    wp_redirect($new_url, 301);
    exit; }
    }

    But I’ve found a new mistake now..

    Original link: https://www.test.com/brands/clothes/
    Translated link: https://www.test.com/en/brands/clothes-2/

    When I switch to the translated site and go to the custom-taxonomy-brands page, this brands page will show all my product brands, I noticed that some of the brands have a ‘-2’ character added to their translated links, not all of them, but some of them.

    If I try to visit https://www.test.com/en/brands/clothes/

    it will 301 jump to https://www.test.com/en/brands/clothes-2/

Viewing 3 replies - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.