Help with understanding writing rewrites
Answered
American black bear posted this in #help-forum
American black bearOP
Hello, I'm trying to understand how rewrites or URLs work generally, I'm just taking examples off of other peoples project, but unsure where to go to understand what these rewrites means.
For example, I see rewrite example below
For the above rewrite, does the & in
For example, I see rewrite example below
`source: /buckets/:pid/:number`,
`destination: /buckets/?pid=:pid&number=:number`For the above rewrite, does the & in
destination act as separator and =: act as like some sort of key and value assignment?Answered by joulev
:thing are dynamic and will be replaced with actual values at request. so for example if the server gets /buckets/foo/bar then it will treat :pid as "foo" and :number as "bar".after that it replaces those in the destination so it becomes
/buckets/?pid=foo&number=bar.?x=y&z=t are just the url query params, e.g. youtube.com/watch?v=abcdef6 Replies
@American black bear Hello, I'm trying to understand how rewrites or URLs work generally, I'm just taking examples off of other peoples project, but unsure where to go to understand what these rewrites means.
For example, I see rewrite example below
`source: /buckets/:pid/:number`,
`destination: /buckets/?pid=:pid&number=:number`
For the above rewrite, does the & in `destination` act as separator and `=:` act as like some sort of key and value assignment?
:thing are dynamic and will be replaced with actual values at request. so for example if the server gets /buckets/foo/bar then it will treat :pid as "foo" and :number as "bar".after that it replaces those in the destination so it becomes
/buckets/?pid=foo&number=bar.?x=y&z=t are just the url query params, e.g. youtube.com/watch?v=abcdefAnswer
American black bearOP
ah gotcha that makes so much more sense, thank you for the simple explanation!
So if the destination becomes
So if the destination becomes
/buckets/?pid=foo&number=bar in my page folder, it will be looking for buckets -> [pid=foo] -> [number=bar] ?@joulev can you clarify your question? i don't quite get this
American black bearOP
gotcha, so with above example where the destination becomes
if my page root looks like below
pages
|_buckets
does that mean that when I render buckets page, I will have query params of
/buckets/?pid=foo&number=barif my page root looks like below
pages
|_buckets
does that mean that when I render buckets page, I will have query params of
pid=foo and number=bar available through router's pagePath?Though the rewrite is usually written for the pathname not the query params so I’m not 100% sure on this. You can always try it