Pretty urls with redirect to another instance

Hi,

I’m trying to redirect an url from an existing instance lacunae to another instance lavouivre:

lacunae.xyz/others/la-vouivre → lavouivre.netlify.app

In _redirects of lacunae, I added this rule:

/others/la-vouivre/*  https://lavouivre.netlify.app/:splat  200

And it is working with https://www.lacunae.xyz/others/la-vouivre/ (trailing slash)

lacunae.xyz/others/la-vouivre will found lavouivre.netlify.app/index.html
but web-app.js will not load as the url will be
lacunae.xyz/others/web-app.js and not lacunae.xyz/others/la-vouivre/web-app.js

In lacunae, I also have that rule that may interfer with Pretty urls

[[redirects]]
from = "/*"
to = "/index.html"
status = 200
force = false
headers = { X-From = "Netlify" }

Or I guess Pretty urls don’t see lacunae.xyz/others/la-vouivre as a folder and don’t add the trailing slash.

Is there a solution to add a trailing slash to https://www.lacunae.xyz/others/la-vouivre and redirect to https://lavouivre.netlify.app ?

You would either need to make sure the resources are in the same place on both sites or set up a redirect so that it looks for the correct place in the site.

Hi,

Thanks for your response.

I’m not sure I can do the first option since it is two different project.
And I would be better to not redeploy lacunae with lavouivre changes.

set up a redirect so that it looks for the correct place in the site.

How would do suggest to do that?
Via the _redirects file?

I would be nice if https://www.lacunae.xyz/others/la-vouivre could redirect to https://www.lacunae.xyz/others/la-vouivre/

@sagix Stepping through what you have…

The reference to web-app.js is defined as ./web-app.js in the HTML

When the page is loaded via:
https://lacunae.netlify.app/others/la-vouivre/

./web-app.js resolves to:
https://lacunae.netlify.app/others/la-vouivre/web-app.js

The _redirects targeting /others/la-vouivre/* cause that to resolve to:
https://lavouivre.netlify.app/web-app.js

The file does exist there.


When the page is loaded via:
https://lacunae.netlify.app/others/la-vouivre

./web-app.js resolves to:
https://lacunae.netlify.app/others/web-app.js

This isn’t targeted by _redirects, and doesn’t exist.
A catch-all redirect appears to be returning the contents of your index.html


I understand this may not be precisely what you’re currently requesting, but there are several ways you could account for what’s happening:

  1. By changing the reference for web-app.js to an absolute URL that would work anywhere, e.g. https://lavouivre.netlify.app/web-app.js

  2. By adding a proxy so /others/web-app.js resolves correctly

    /others/web-app.js  https://lavouivre.netlify.app/web-app.js  200
    
  3. You could try a redirect exactly like you’ve suggested (but I’m unsure if it would work)

    /others/la-vouivre  /others/la-vouivre/  301
    

Hi Nathan,

Thanks for your help.
I don’t want to go into 1 or 2, because it means that I would have to do that for all resources (I plan to had images too)

I tried 3, but it is not intended to work:

# This rule will cause an infinite redirect
# because the paths are effectively the same
/blog/remove-my-slashes/   /blog/remove-my-slashes  301!

For now the workaround I found is to do a redirection via a html script in lavouivre index.html

<script>
    if (window.location.pathname.slice(-1) !== '/') {
        window.location.replace(
            window.location.href.replace(window.location.pathname, window.location.pathname + '/')
        );
    }
</script>

Not pretty but it is working :sweat_smile:

1 Like

Hi @sagix :wave:t6: glad to hear it!

@sagix Nice workaround.

As I understand it, the trailing slash is supposed to operate as outlined here:

https://answers.netlify.com/t/support-guide-how-can-i-alter-trailing-slash-behaviour-in-my-urls-will-enabling-pretty-urls-help/31191#with-a-file-at-bloghtml-5