Struggling with simple redirect in user/config/site.yaml

Hi, I would appreciate help with my newbie problem of struggling to get a simple redirect to work in /user/config/site.yaml.

I’ve tried possible solutions in various posts here to no avail (partly I have been getting confused is to whether I need to use quotes within the redirects as some examples do and some don’t).

I am attempting to redirect from
mysite.com/article2 to
mysite.com/blog/weve-applied-for-charitable-status

But am getting 404 errors no matter how much I play around with with they syntax.
(BTW, /blog/weve-applied-for-charitable-status does actually exist and article2 does not. )

This is what I currently what I have in /user/config/site.yaml

blog:
route: /blog
redirects:
‘/article2’: ‘/blog/weve-applied-for-charitable-status/’

Any help gratefully appreciated. :slight_smile:

William

Is Grav running at the root of your site? Or is it only handling files under /blog? Unless it’s processing your entire site, then your redirects won’t do anything. I don’t use redirects myself, so I can’t speak specifically to syntax.

Quotes in YAML are only needed to contain certain characters. If you’re ever unsure, you can paste your YAML into a linter like http://www.yamllint.com/ and it will tell you if you’re missing necessary quotes.

Grav is running at the root of the site as the whole site is Grav based.

Thanks for your question to clarify things, the tip about the quotes and the link to the YAML linter - very handy to know about.

:slight_smile: William

So I’m confused about the contents of your site.yaml because of the formatting. Is the rest of your YAML block under blog? The first two lines don’t belong in site.yaml. Lines 3/4 on their own should work assuming you indent line 4 with spaces.

I’ve ended up creating the missing pages and just applied the redirect on the Front Matter of each page:

redirect: ‘/newdir/mynewpage[301]’

You are right hughbris, I was missing the spaces in front of the redirect. Thanks for that. However, when I added the spaces the redirects still don’t work. I still get directed to the 404 error page.

I think am out too of my depth and I better just stick to on-page redirects for now. :slight_smile:

BTW, today I came across another site.yaml which was in /system/config/site.yaml
It has examples of what I was trying to do. I also saw that it had the “redirects:” listed before the “blogs:” entry. Also it uses two space chars to indent rather than 4. I tried various combinations but redirects still go to 404 error page on my site. Therefore I’ll stick to the on-page workaround for now.

Thank you Perlkonig and hughbris for you comments and suggestions.

Cool, go with what works. As little as I know about or like YAML, pretty sure it doesn’t care how many spaces you use as long as you are consistent.