I would like to add a REST route that would looks like


where XXX is an URL.

I had a try with

register_rest_route('.../v1','import/?url=(?:/(?P<url>\w+))?', array(
            'methods'             => WP_REST_Server::READABLE,
            'callback'            => array( $this, 'import_url' ),
            'args' => array(
                'url' => array(
                    //'validate_callback' => array($this, 'validateImportUrl')
    ) );

but it does not work:

{"code":"rest_no_route","message":"No route was found matching the URL and request method","data":{"status":404}}

Can anyone help ?

Thanks !

  • Query parameters don't belong in the route, they should be added as arguments, which you've already done. Jun 20, 2019 at 1:40

1 Answer 1


Regex problem, I found out :)

register_rest_route( '.../v1', 'import(?:/?url=(?P<url>\d+))?', array(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.