#Hello everyone, please advise. I am using hybrid mode and I have a problem with redirects. My enviro

4 messages · Page 1 of 1 (latest)

forest parcel
#

Hello everyone, please advise. I am using hybrid mode and I have a problem with redirects. My environment works through nginx. Pages that are marked as ssr - work for me, but redirects do not work, although they get into the manifest. On the local host, in preview mode, everything works.

My config looks something like this now.

if ($host = www.site.name) {
return 301 https://www.site.name$request_uri;
}

    location ~ ^/(search|en/search|preview|en/preview) {
            proxy_pass http://127.0.0.1:4321;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
    }

error_page 404 403 500 503 /404.html;
location = /404.html {
    #root /home/dev/site.name/dist/client;
    #internal;
    proxy_pass http://127.0.0.1:4321;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
}

}

server {
if ($host = site.name) {
return 301 https://$host$request_uri;
}

if ($host = www.site.name) {
    return 301 https://$host$request_uri;
}

listen 80;
server_name site.name www.site.name;
return 404;

}

worthy dawnBOT
#

Hi @forest parcel. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the knowledge sources provided, it seems that there are a few potential issues that could be causing your redirects not to work in Astro's hybrid mode.

  1. Redirects should be handled by the server: In hybrid mode, redirects should be handled by the server, not by Astro. This means that the file for the redirect shouldn't be generated at all (source (https://github.com/withastro/astro/issues/8500)).

  2. Redirects in static mode: Astro has a build option build.redirects that specifies whether redirects will be output to HTML during the build. This option only applies to output: 'static' mode; in SSR redirects are treated the same as all responses. This option is mostly meant to be used by adapters that have special configuration files for redirects and do not need/want HTML based redirects (source (https://docs.astro.build/en/reference/configuration-reference/#buildredirects)).

  3. Redirects and prerendering: If you're using prerendering, you might need to opt-out of prerendering for the redirects to work correctly (source (https://github.com/withastro/astro/issues/10922)).

  4. Redirects and dynamic routes: If you're using dynamic routes, they might interfere with the redirects. One user reported a similar issue and ended up handling their own set of redirects with a json and a src/pages/**...redirect].astro, which worked for them ([source** (https://github.com/withastro/astro/issues/7581)).

#

Without more specific information about your setup and the exact issues you're encountering, it's hard to provide a more detailed answer. However, I hope these points can help you troubleshoot the issue. If you're still having trouble, I would recommend opening an issue on the Astro GitHub (https://github.com/withastro/astro/issues) for more specific help.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: