Issue with Netlify Redirects and URL Path Preservation

Hello,

I have set up a redirect rule in my netlify.toml file to redirect requests from a subdomain to a Github Repository while preserving the original URL path. However, I’m encountering an unexpected behaviour when clicking links in the redirected page. When clicking on any URL in the page, it includes an additional path segment, causing 404 errors.

Here’s an example of the netlify.toml configuration:

[[redirects]]
from = "https://github.website.com/*"
to = "https://github.com/orgName/repoName/:splat"
status = 200
force = true

My intention with this configuration is to redirect URLs from “https://github.website.com/” to “https://github.com/orgName/repoName/”, but when I click on links, the redirected URLs end up like this:

So the end point ends up being :

As a result, I’m encountering 404 errors due to the unexpected addition of “/orgName/repoName/” to the URL path.

I would like to understand how I can modify my Netlify redirect configuration to ensure that the redirection works as intended without adding the extra path segment.

Thank you for your assistance in resolving this issue.

Hi @F1n , thanks for the post and welcome to the Netlify Support Forums.
Based on what you are experiencing it means /orgName/repoName/ is the clickedPath.
If thats the case then your netlify.toml redirect configuration should rather be like the below

[[redirects]]
from = "https://github.website.com/*"
to = "https://github.com/:splat"
status = 200
force = true

Make the changes and then try it out to see if it works.

Let me know the outcome.
Thanks.

Hi @clarnx,

Thank you for your response. However, I have tried and understand changes you recommended, it appears that the redirection still isn’t achieving the desired result. Let me clarify my intention:

I want the subdomain “github.website.com” to point to a specific GitHub repository, “github.com/orgName/repoName,” rather than redirecting to the entire GitHub website.

In other words, I want any request to “github.website.com” to take the user directly to “github.com/orgName/repoName” without adding any extra path segments (github.website.com/orgName/repoName/).

Here’s an example of the configuration I currently have in my netlify.toml file:

[[redirects]]
from = "https://github.website.com/*"
to = "https://github.com/:splat"
status = 200
force = true

With this configuration, the subdomain redirects to “github.com”, which is not the desired outcome.

I appreciate your assistance in resolving this issue.
Best regards

Thanks for the extra information @F1n

Based on what you want to achieve above kindly try the configuration below.

[[redirects]]
from = "https://github.website.com"
to = "https://github.com/orgName/repoName"
status = 200
force = true

Let me know the outcome.
Thanks.