-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need URL rewrite to add trailing slash #563
Comments
same issue @emilevauge is this a bug? |
Think should be a feature. Although you.probably want it most of the time, and begins does it by default if you use it as reverse proxy. Expected behaviour is explained in my original post. |
I also have the same issue |
Hi, this is due to the underlying muxer used in traefik http://www.gorillatoolkit.org/pkg/mux#Router.StrictSlash. We use it with
We need to work on this indeed... |
I was able to workaround this issue using the regex on the entrypoint: defaultEntryPoints = ["http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
regex = "(http:\\/\\/[^\\/]+\\/([^\\?]+)[^\\/])$"
replacement = "$1/" The redirection is fine but I ran into #679 :( |
I have a similar issue here: #1123 |
same issue #1106 |
Many issues are related to this. |
@emilevauge I hate to just add noise to this issue - but host based routing isn't really an option for us. Our customers have too many http proxy/firewalls in the way... Certainly we can organise html data such that the webserver container responds correctly with the full path but it pollutes the deployment - adding 'brittleness' since if we change the deployment path we have to change the data organisation to reflect the path and/or add configuration to what would otherwise be a trivial deployment... |
Closed by #1638, in the version 1.3.0-rc3. |
@ldez could you please clarify how to achieve a 301/302 redirect from My current igress spec: apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: my-app
annotations:
kubernetes.io/ingress.class: traefik
traefik.frontend.rule.type: PathPrefixStrip
# need something else here?
spec:
rules:
- host: example
http:
paths:
- path: /app
backend:
serviceName: my-app
servicePort: http There is a dirty workaround for nginx in kubernetes-retired/contrib#1884 (comment), but I haven't found anything similar for traefik. Could not understand what to add to my spec after reading the docs and #1638. When I use |
I confirm this was resolve when Emile officially released the fix about 3 months ago. |
@pascalandy do you mean that traefik automatically redirects from |
Enjoy this setup :) |
@pascalandy I don't know if you have see: we created https://github.com/containous/traefik/wiki/Awesome-Traefik. |
Thanks for the links guys. Not sure my kubernetes-specific question is answered in that material though :–) |
Not sure this was answered either. Did you find a way to go from http://example/app to http://example/app/ @kachkaev? |
No, unfortunately. I still can't configure a separate backend at |
Any ideas? |
Here is my current solution for k8s until I find something better 😆 Meet namespace ## add-trailing-slash.yaml
---
apiVersion: v1
kind: ConfigMap
metadata:
name: add-trailing-slash
namespace: redirects
data:
default.conf: |
server {
server_name $host;
rewrite ^(.*) $scheme://$host$1/ permanent;
}
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: add-trailing-slash
namespace: redirects
labels:
part: add-trailing-slash
spec:
replicas: 1
template:
metadata:
labels:
part: add-trailing-slash
spec:
containers:
- name: main
image: nginx:1.13.6-alpine
volumeMounts:
- name: nginx-config
mountPath: /etc/nginx/conf.d/
volumes:
- name: nginx-config
configMap:
name: add-trailing-slash
---
apiVersion: v1
kind: Service
metadata:
name: add-trailing-slash
namespace: redirects
labels:
part: add-trailing-slash
spec:
ports:
- port: 80
name: http
selector:
part: add-trailing-slash kubectl apply -f add-trailing-slash.yaml
CASES=(
example.com/path1
another.example.com/path2
)
for CASE in "${CASES[@]}"; do
IFS='/' read CASE_DOMAIN CASE_PATH <<< "$CASE"
echo "
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: add-trailing-slash-for-${CASE_DOMAIN}--${CASE_PATH//\//-}
namespace: redirects
spec:
rules:
- host: ${CASE_DOMAIN}
http:
paths:
- path: /${CASE_PATH}
backend:
serviceName: add-trailing-slash
servicePort: http
" | kubectl apply -f -;
done; Thankfully I don't have that many client-facing microsercices that start with |
Thanks @MindTooth @jvenezia you're sure about your latest config? |
@MindTooth I should have told I was using Ansible, not docker compose. The syntax is a bit different. With docker-compose, it should look like that:
As you mentioned, you maybe need double the Did that work for you @pascalandy? Working like a charm form me! |
No worries. Works like a champ AFAIK. Thanks to the both of you. |
I tried few possibilities and still have the same error:
|
You can easily try my configs here |
@pascalandy: Care to try with |
error:
config:
|
What happens if you change the second line of your config from:
to:
(escaping the $ with a second $)? |
works!!!
|
Woo hoo! |
Thank you so much guys! @hartzell @MindTooth @jvenezia I merged/squashed this change to master :) |
@ldez I believe this trailing "/" issue should be part of the docs as an example. Cheers! |
@pascalandy maybe your first first pull request 😃 ? |
Sure, please point me in which section should this doc appear and I'll do it! |
I think you can add a new section here https://github.com/containous/traefik/blob/master/docs/user-guide/examples.md |
See PR here: #3891 |
I created a docs issue #4221 with a similar problem - i think we should document, as a table, all the variations of each matcher and replacer, and when they would apply, and how they would change the request on the backend. Would love to get feedback from the experts here :) |
How to do this using file config instead of docker-compose? Doesn't seem to work due to different variables |
Ditto, would be interesting to do this using file config |
@romprod, @tiagoefreitas -- What have you tried? Can you show us a nearly working example? |
I have this working now, I'll post my config when I get back after the weekend hopefully |
Working code to translate 192.168.0.1:9000 to 123.co.uk/portainer
|
I needed something backward compatible to 1.4 - Tested on 1.4.6 and 1.6.6 regex matches and strips on Alternately, similarly to drop the prefix: |
This is killing me. How am I supposed to employ this kind of rewriting site wide? I do not want to create regex for tens of apps. I am wondering why this is still not considered an optional thing. |
I have a simple app, which has the following file structure at root
script.js
andstyle.css
)Since I want to access the app via URL
http://example/app
, I proxied the web app with rulePathStripPrefix:/app
. The problem is when I try to access URLhttp://example/app
(without trailing slash), it will load "index.html" fine, but not the JS and CSS file. When I look into the debugger, it tries to load:Instead of (the correct one):
It only works when I type the original URL with a trailing slash, so
http://example/app/
. This is not a big deal for me but users sometimes find it annoying since we used to use Nginx, who sends an "301 Moved Permanently" to a URL with trailing slash when it's not there. I wonder if it is possible / makes sense to implement this in Traefik?Thank you!
The text was updated successfully, but these errors were encountered: