Support » Developing with WordPress » Remove Trailing Slash From Rewrite Rule

  • Resolved crgeary

    (@crgeary)


    I’m trying to setup a custom rewrite rule. If I use the below:

    
    add_action('init', function () {
        add_rewrite_rule('manifest.webmanifest(/.*)?$', 'index.php?'.Manifest::QUERY_VAR.'=1', 'top');
    });
    

    It creates a my custom endpoint, however WordPress adds a trailing slash so that my URL end up like this: /manifest.webmanifest/

    Iideally I want it to be /manifest.webmanifest.

    How would you fix this for this one url? Keeping in mind, I still want my pages/posts to have trailing slashes.

    • This topic was modified 2 years, 6 months ago by crgeary.
Viewing 1 replies (of 1 total)
  • Thread Starter crgeary

    (@crgeary)

    Problem solved.

    
    add_filter('redirect_canonical', function ($redirect, $request) {
        if (1 == get_query_var(Manifest::QUERY_VAR)) {
            return false;
        }     
        return $redirect;
    }, 10, 2);
    
    • This reply was modified 2 years, 6 months ago by crgeary.
Viewing 1 replies (of 1 total)
  • The topic ‘Remove Trailing Slash From Rewrite Rule’ is closed to new replies.