I have a HTML called users.html. That HTML contains a JS script that fetches a user’s information on the server. It gets the username using the URL. For example:
webpage.com/users/kibebr or webpage.com/users.html/kibebr
the JS script reads the kibebr and fetches the data.
It’s working great on my computer but how can I use Netlify redirects to achieve the same?
I have tried:
[[redirects]]
from = "/users/*"
to = "/users"
status = 200
force = false
headers = {X-From = "Netlify"}
When I go to webpage.com/users the server rejects it, works fine!
However, when I add a slash like webpage.com/users/kibebr, I get
@kibebr It’s a little unclear what you’re trying to do. Your redirect tells Netlify that anyone who tries to visit /users/kibebr should instead be sent to /users. If you want the user name to be used in a new URL somehow, then you must have something like to = "/users.html/:splat".
@kibebr OK, so you’re not actually redirecting to another page? I think you’re going to have to stick with your JavaScript solution because redirects seem not to be designed for this task.
Yep, seems like redirects aren’t actually necessary. I have tried removing all redirects and the “issue” is that when I type in webpage.com/users/theusername, Netlify reads theusername as another page, and tries to get theusername.html.
Basically I’m trying to make theusername a query, just like webpage.com/users?name=theusername (this works fine with the necessary modifications)
but I’m not sure if Netlify supports it using only slashes: webpage.com/users/theusername
And thank you once again for taking your time to look into this
I think the cleanest solution here would be query parameters which would result in a URL such as webpage.com/users?theusername. You won’t need to do this but, if you need to redirect them in future, we support query parameter redirects.