unit icon indicating copy to clipboard operation
unit copied to clipboard

PHP: Routes uri match and trailing slash

Open lucatacconi opened this issue 2 years ago • 3 comments

I'm configuring a route as follow for a php application: { "app2" : [ { "match":{ "uri": ["/test/*"], "method": "GET" }, "action":{ "pass": "applications/app2" } } ] }

with a basic listener: "listeners": { "*:8080": { "pass": "routes/app2" } },

Accessing route by browser i can test correctly the application by the following address http://SERVER_IP:8080/test/ Is it possible to avoid trailing slash in the address (ex http://SERVER_IP:8080/test)? I tried changing the uri match from "uri": ["/test*"], to "uri": ["/test*"] but the result is the same: Error 503.

Thanks in advance.

lucatacconi avatar Jun 08 '22 15:06 lucatacconi

Can you please share the unit.log as well as the whole unit configuration? That will help to trace down the issue. Thanks

tippexs avatar Jun 08 '22 17:06 tippexs

Hi @lucatacconi

I suggest testing pure matching first. For example:

{
    "listeners": {
        "*:8080": {
            "pass": "routes"
        }
    },
    "routes": [
        {
            "match": {
                "uri": "/test*"
            },
            "action": {
                "return": 206
            }
        }
    ]
}

If it doesn't match, it will return 404. I just tested and it works. If it returns 503, it shows that the route is matched, but the application doesn't work, you need to check its service.

hongzhidao avatar Jun 09 '22 03:06 hongzhidao

@lucatacconi Could you test this patch? It should allow you to access the URL without a trailing '/'.

You can test it with your original config with the match as "/test*".

ac000 avatar Sep 19 '22 21:09 ac000

The fix for this has been merged. a032744

ac000 avatar Nov 02 '22 15:11 ac000