Url_rewrite with full url doubles path

Hello,

my relative url rewrite works fine

match: /my/articles
rewrite_to: /v1/articles

but as soon as i use a full url:

rewrite_to: http://api.mydomain.com:3000/v1/articles

it stops working and Log browser shows path “/v1/articles/v1/articles”

Any idea for a fix or a workaround?
Thank you.

Hi Juraj,

can you share your API definition ?

Thanks,
Kos @ Tyk Support Team

Sure, the whole definition is huge, but this part should be sufficient, let me know if anything’s missing:

{
"id": "5926e21fecf5062f105d61ff",
"name": "Music Cloud",
"slug": "music-cloud",
"api_id": "1df465f1826a478466d3b332d60a02fd",
"org_id": "5909eaeaecf50606045d9f05",
"use_keyless": false,
"use_oauth2": false,
"use_openid": false,
"openid_options": {
    "providers": [],
    "segregate_by_client": false
},
"oauth_meta": {
    "allowed_access_types": [],
    "allowed_authorize_types": [],
    "auth_login_redirect": ""
},
"auth": {
    "use_param": true,
    "param_name": "",
    "use_cookie": false,
    "cookie_name": "",
    "auth_header_name": "api_token"
},
"use_basic_auth": false,
"enable_jwt": false,
"use_standard_auth": true,
"enable_coprocess_auth": false,
"jwt_signing_method": "",
"jwt_source": "",
"jwt_identity_base_field": "",
"jwt_client_base_field": "",
"jwt_policy_field_name": "",
"notifications": {
    "shared_secret": "",
    "oauth_on_keychange_url": ""
},
"enable_signature_checking": false,
"hmac_allowed_clock_skew": -1,
"base_identity_provided_by": "",
"definition": {
    "location": "url",
    "key": "x-api-version"
},
"version_data": {
    "not_versioned": false,
    "versions": {
        "v0.9": {
            "name": "v0.9",
            "expires": "",
            "paths": {
                "ignored": [],
                "white_list": [],
                "black_list": []
            },
            "use_extended_paths": true,
            "extended_paths": {
                "white_list": [
                    {
                        "path": "/me/artists",
                        "method_actions": {
                            "GET": {
                                "action": "no_action",
                                "code": 200,
                                "data": "",
                                "headers": {}
                            }
                        }
                    },
                  ...
                "url_rewrites": [
                    {
                        "path": "/me/artists",
                        "method": "GET",
                        "match_pattern": "/me/artists",
                        "rewrite_to": "http://api.mydomain.com:3000/v1/artists"
                    },

you don’t need to include your host in rewrite_to.
So if you remove that (so you’ll have "rewrite_to": "/v1/artists") then /me/artists should be rewritten to /v1/artists.
If you are still having issues, you may also check this ticket which has been resolved.

Let me know if you need any further help.

Thanks,
Kos @ Tyk Support Team

Sorry Kos, but i do have to use the full url, because the default Target URL
has a different port (3001). And for some URLs, i need to go to port 3000.
I think it’s a bug, that Tyk gateway rewrites this path to
http://api.mydomain.com:3000/v1/artists/v1/artists

Hi,

Does it work if the target and the rewrite domains are completely different (apart from the port?)

M.

Hi Martin,

it doesn’t work either. I tried both a different domain/port, and a differnt domain without a port number.
Both responses clearly show a request path “/v1/artists/v1/artists”

Juraj

Ok thanks for confirming - we’re going to try and replicate to see if there’s a regression somewhere.

We’ve been able to reproduce this and we’re tracking the issue over at GitHub: https://github.com/TykTechnologies/tyk/issues/855

1 Like