No trailing slash when using proxies

Hello,

We have a large website that we split up into multiple Netlify sites. Our main site is www.dokteronline.com which we use to handle redirects and proxy to all the 9 (language) subsites.

We have Pretty URL optimization activated on all the subsites, and when visiting a page without a trailing slash on this subsite it gets redirected to the URL with the trailing slash. (ex: https://dokteronline-pt.netlify.app/pt/saude-dos-homens)

The problem is that this does not work on the main site when using proxies. (ex: SaĂșde dos homens | Testosterona | Disfunção erĂ©til | Dokteronline.com)
I have read that this is a known issue so I am curious if there is any update or some kind of workaround to this. Right now it is hurting our SEO.

Greetings,
Jorik

1 Like

This is interesting. Pretty URLs is not supposed to do that:

Ok, I might have misunderstood that part.

But the problem still remains that the 301 redirects are working when visiting the Netlify site directly, but they are not working when visiting the site when using Netlify proxies.

dokteronline-pt.netlify.app >> redirect is working
dokteronline.com/pt >> [proxy redirect to dokteronline-pt.netlify.app] >> redirect is not working

I believe the redirects in the netlify.app subdomain is because the file being served is /saude-dos-homens/index.html. So technically /saude-dos-homens should return a 404 as browsers would look for /saude-dos-homens.html. But Netllify normalises this and serves /saude-dos-homens/index.html.

The behaviour that you see on dokteronline.com/pt is expected. We’re proxying to the destination URL and are able to serve the file from there. When we normally make proxy rewrites, we respect the 301 header and redirect, but in the case I explained in the paragraph before, the 301 is getting ignored as that’s a 301 set automatically by us and not by the user.

To solve SEO issues, I think you should add canonical tags.

I think that I have observed the same bug.

curl -I https://docs-v5--material-ui-x.netlify.app/x/advanced-components is a 301 to https://docs-v5--material-ui-x.netlify.app/x/advanced-components/ where the underlying file served is /x/advanced-components/index.html

However, when we use a proxy: (/x/* https://docs-v5--material-ui-x.netlify.app/x/:splat 200) then the trailing slash auto redirection does not longer work.
Proof: curl -I https://mui.com/x/advanced-components is a 200.

Hi @oliviertassinari :wave: ,

The two sites you referenced appear to have different asset optimization settings. To resolve the issue, you’ll need to:

  1. figure out which site works the way you want, then go to the other site and
  2. uncheck the ‘Disable asset optimization’ setting in Site settings > Build & deploy > Post processing > Asset optimization
  3. mirror the settings from the working site
  4. recheck the ‘Disable asset optimization’ setting

You may be wondering why you need to disable and then re-enable asset optimization. We have an open bug and disabling and re-enabling is the workaround until we can roll out a fix!

Apologies we don’t have any docs on this, but you may want to check out our support guide on trailing slash behavior to get a better understanding.

Hope this helps and do let us know how it goes! :slight_smile:

I have updated the new sites to have the exact same asset optimizations and redeployed. It didn’t solve the problem. @audrey I think that this could be turned into a bug.

@jorik12345 Did you solve the issue on your end?

Hey @oliviertassinari,

This looks related to an issue we’ve already filed for investigation and we’re waiting on its response to debug this further.

Hey @oliviertassinari,

Sorry for the delay. We think we know what is happening and have an explanation. Let us know if it makes sense to you. TL;DR, what you’re seeing is probably the way you want this to work instead of the other way it would work. Here goes the explanation:

When you use Netlify’s Proxy feature, we respect the headers sent by the destination server. For example, consider the following situation:

  1. You setup https://my-proxy.netlify.app/ to proxy to https://www.google.com/
  2. You visit https://my-proxy.netlify.app/ and expect to see https://www.google.com/.
  3. https://www.google.com/ sends a 301 status code and redirects the client to https://www.youtube.com/
  4. Netlify would respect those headers and send a 301 to redirect to https://www.youtube.com/. Basically, the URL in the address bar would now show https://www.youtube.com/ and not https://my-proxy.netlify.app/.

In your case though, we actually send a 301 on the proxy destination. But, we treat internal proxies a bit differently than external proxies. So, we are able to normalise the URL and send a 200 response. Instead, if we send a 301 like we do for the actual site, the proxy would break and you’d be 301 redirected to the destination URL. This is not something you probably want.

We can add this as a feature request to support handling this 301 differently, but I don’t think there would be any immediate actions about this.

2 Likes

Thanks for the update. This makes a lot of sense. There might be an opportunity for the proxy to be smart about trailing slash redirections.

I will wait for a fix.

1 Like

I think that I have found another manifestation of how Netlify handles internal redirects differently than external ones. When the URL has a case issue, e.g.

https://mui.com/material-ui/getting-started/overvieW/ get redirected to https://mui.com/material-ui/getting-started/overview/

However, when the URL is a proxy, this doesn’t work, e.g. https://mui.com/x/react-Date-pickers/Date-range-picker/.

We could look into using two different hosting providers to get this fixed (so it’s no longer an internal redirect).

HI @oliviertassinari welcome back. Thanks for sharing this with the community.

Because it is not possible to create 301 redirects to get a trailing slash in netlify.toml, it is a nesseccary feature for us to enable 301 forwarding if we use the internal proxy to get content from servers outsite of netlify.

I think this is often needed for migration tasks to netlify.

Please add this feature.

It is possible to use Pretty URLs to get 301s for trailing slash.

Hello hrishikesh,

PrettyUrls are not working when content is served from external Servers via netlify proxy.

For example
https://www.stayery.de/impressum
no redirect to
https://www.stayery.de/impressum/

My netlify.toml file

[[redirects]]
from = “/impressum/*”
to = “https://typo3.stayery.de/impressum/:splat”
status = 200
force = true

Thanks a lot for any ideas.
My last information is that there is no solution for this problem. Whis makes our customer unhappy.

Hi, @tom_morello. The redirect rule is redirecting this URL:

https://www.stayery.de/impressum

To this URL:

https://typo3.stayery.de/impressum/

It is redirecting a non-trailing slash URL to a URL with a trailing slash (redirecting to https://typo3.stayery.de/impressum/).

That URL with the trailing slash returns a 200 status. That 200 status is then returned to the client. There is no 301 redirect because the proxy target sends a 200 not a 301.

The solution for this will be to add one more redirect before the one above like so:

[[redirects]]
  from = “/impressum”
  to = “https://typo3.stayery.de/impressum”
  status = 200
  force = true


[[redirects]]
  from = “/impressum/*”
  to = “https://typo3.stayery.de/impressum/:splat”
  status = 200
  force = true

If that doesn’t resolve the issue or if there are any question, please let us know.

Hallo luke,

Your solution is live now!

Still no 301 redirect for the enduser browser to impressum/ from impressum

image

Kind Regards

Hallo luke,

this solution can not work, because the enduser should stay on www.stayery.de
and should not be redirected to typo3.stayery.de

typo3.stayery.de delivers only content with a {x-header:“www.stayery.de” } set.

After the 301 redirect the user requests typo3.stayery.de without a x-header set.

Kind Regards

I’m missing a important Feature

PrettyUrls are not working when content is served from external Servers via netlify proxy.

For example
https://www.stayery.de/impressum
no 301 redirect to
https://www.stayery.de/impressum/

My netlify.toml file

[[redirects]]
from = “/impressum/*”
to = “https://typo3.stayery.de/impressum/:splat”
status = 200
force = true

Right now I’m not shure If Luke understood my Problem.

It looks like a important feature is missing.

Any suggestions?
Thanks a lot for any ideas.

Yup, we don’t intend to support automated trailing slashes on remote resources that we proxy to - we don’t try to change the proxy’d response at all.

I think you’ll need to implement a 301 on the server at typo3.stayery.de if the content you serve from there requires this.