Use of placeholders and splats

Just want to check I have used the redirect placeholders and splats correctly (in terms of syntax) before I publish the redirects and push the site live. Can anyone confirm.

The example in docs uses :year, month: slug: etc so i just want to make sure I can use anything as a placeholder and it doesn’t have to be from a built in subset or anything. In my case i want to use :topic for the various topics that appear after articles/topics/ and prior to the page(splat:) stuff

I am aware that forward slashes are not necessary and that netlify will check for both with and without but ii added them just for completeness

https://silly-knuth-4897cf.netlify.com/ - is instance name

/articles/all /articles/ 301
/articles/all/* /articles/page/:splat/ 301
/articles/topics/:topic /articles/topics/:topic/ 301
/articles/topics/:topic/* /articles/topics/:topic/page/:splat/ 301

Hi @DaveHarrison. The syntax is those rules is correct and they work when I test them. Note, they are not active on that site linked to at this time.

However, if they were active that fourth rule would redirect this:

https://silly-knuth-4897cf.netlify.com/articles/topics/foo/bar

Here:

https://silly-knuth-4897cf.netlify.com/articles/topics/foo/page/bar/

​Please let us know if there are other questions about this.

1 Like

Now that have the redirects activated I am getting the following issue

When I enter https://silly-knuth-4897cf.netlify.com/articles/topics/web-design/1

I get

https://silly-knuth-4897cf.netlify.com/articles/topics/web-design/page/page/page/page/page/page/page/page/page/page/page/page/page/page/page/page/page/page/page/page/1////////////////////

is there some sort of crazy redirect loop going on where the redirects are conflicting?

OK I think I see the problem, it is how my new hierarchy of files handles the first page of any collection. The /page/:splat only kicks in from page 2 onwards and bypasses page 1 so i have added a few rules to handle those cases which i think if I’m correct will in those instances ignore the rule below with the placeholder and splats!

Aghhh
no all that has happened is that the issue has bypassed page 1 whcih I added new rule for so
https://silly-knuth-4897cf.netlify.com/articles/topics/web-design/2 now sends me in a weird redirect loop instead of redirecting to https://silly-knuth-4897cf.netlify.com/articles/topics/web-design/page/2/
Can you see where I have gone wrong?

/articles/all /articles/ 301
/articles/all/1 /articles/ 301
/articles/all/* /articles/page/:splat/ 301
/articles/topics/:topic /articles/topics/:topic/ 301
/articles/topics/:topic/1/ /articles/topics/:topic/ 301
/articles/topics/:topic/* /articles/topics/:topic/page/:splat/ 301

Wait! Could it be because its going to a 404 instead?, i.e the 2nd page of web-design articles doesn’t exist?

Hi, @DaveHarrison, there is a 404 because no redirect is applying. I agree that this rule should match:

/articles/topics/:topic/* /articles/topics/:topic/page/:splat/ 301

However, I also don’t show that rule active at this time for that site.

These are all the rule which match a starting path of /articles for the currently published deploy:

/articles/all  /articles/ 301
/articles/all/1  /articles/ 301
/articles/all/* /articles/page/:splat/ 301
/articles/topics/:topic /articles/topics/:topic/ 301
/articles/topics/:topic/1/  /articles/topics/:topic/ 301

The path of /articles/topics/web-design/2 doesn’t match any rule above (but it would match the :splat rule if it was active).

Thanks for clarification @luke . I removed the

/articles/topics/:topic/* /articles/topics/:topic/page/:splat/ 301

rule as I couldn;t understand the redirect loop!

I’ve reinstated the above rule in the redirects so you can troubleshoot it?
Dave

@luke I reinstated the rule and still get a weird redirect loop. can you look it over and advise if this is netlify specific. thanks so much

Hi, @DaveHarrison. I see this rule here:

/articles/topics/:topic/* /articles/topics/:topic/page/:splat/ 301

Redirecting this path:

  • /articles/topics/web-design/2

to:

  • /articles/topics/web-design/page/2/

Here, :topic matched web-design and * matched 2.

However, then the same rule redirects this

  • /articles/topics/web-design/page/2/

to:

  • /articles/topics/web-design/page/page/2//

This time :topic matched web-design and * matched page/2/.

I think the solution for this is a rule like so:

/articles/topics/:topic/:page /articles/topics/:topic/page/:page/ 301

This should still redirect as expected but no longer loop. If this doesn’t work, we’re happy to keep troubleshooting.

1 Like

@luke that seems to work, i.e no more redirect loop. It is currently going to a 404 as the pagination not in place but this is expected and it now means if i reintroduce the paging, this redirect will work great

1 Like