Routing with SubDirectory (Host + Path)

In reference to:

I implemented the suggestion in the answer using (which is what is also in the traefik docs)

Host(``) && Path(`/path`)

but it does not work (Getting 404 when trying to access it).

Traefik logs show:

time="2020-07-07T10:31:30Z" level=error msg="field not found, node: rule " providerName=docker

My docker compose looks like this:

    - "traefik.enable=true"
    - "traefik.http.routers.typo3-${NAMEOFSERVICE}.rule = Host(`${HOSTNAME}`) && Path(`${DIRECTORY}`)"

When just using with the Host rule it works perfectly fine. But I want to be able to do e.g. for service 1 and for service 2

I also tried - "traefik.http.routers.typo3-${NAMEOFSERVICE}.rule = Host(`${HOSTNAME}`) && PathPrefix(`${DIRECTORY}`)" but I get the same error in the log and 404.

Check the service labels with a docker inspect. Based on the error I suspect one or more of the variables are not set.

Alternatively try replacing the variables in the stack file with actual values.

1 Like

Thanks for your input. I just tried with manually putting in the variables. I still get 404 and the field not found-error.

.yaml looked like this, this time

        - "traefik.enable=true"
        - "traefik.http.routers.typo3-test.rule = Host(``) && PathPrefix(`/foo)"

Also tried with just Path instead of PathPrefix and still same behaviour.

Ok I found the problem. The spaces before/after the .rule "=" caused the issue.

This works:

- "traefik.http.routers.typo3-${NAMEOFSERVICE}.rule=(Host(`${HOSTNAME}`) && Path(`${DIRECTORY}`))"

I now have another problem tho. My service on redirects to --> 404 how do i solve that?

More detailed:
I have a Typo3 Stack where when opening the first time I am redirected to the setup. When accessing I get redirected to --> I am not in the subdirectory anymore and thus it does not work.

Unfortunately not all softwares work out of the box with a Proxy like this. There may be additional settings required for custom paths like this.

Could you help me with that?

I tried the pathprefix middleware but when accessing e.g. the service gets a /apache/ request instead of just /