Combining permalinks & aliases

my company website has been live for many years with the address pattern for our blog posts as /blog/slug

i am told by our dev that it is better for SEO to just have /slug

i can do this with:

[permalinks]
    blog = "/:slug"

but then all of my existing blog post links get a 404 error. it seems like aliases are the best approach.

my thought was to do this to every blog post:

+++
...other params...
aliases = "/blog/:slug"
+++

but that doesn’t appear to work. maybe i’m not calling the slug variable properly.

any ideas for a functional equivalent to what i’m trying to accomplish? (i’d rather not have to type out the alias for every single blog post.)

thanks!

This might save you some time:
https://support.cloudflare.com/hc/en-us/articles/200172286-Configuring-URL-forwarding-or-redirects-with-Cloudflare-Page-Rules

appreciate it, thank you! that was my backup option if there is no elegant way to do in hugo.

You want to handle this on the server side.

can you explain your thought process on why it is better to handle w/ DNS than Hugo?

my understanding was that 301s get penalized by search engines. since the purpose of the permalink would be to help SEO, i thought maybe a hugo alias (relevant code below for ease of reference) would be more SEO friendly than a 301 - but I really know nothing about what is considered a best practice.

(this is what the alias is doing, from the docs)

    <meta name="robots" content="noindex">
    <meta http-equiv="refresh" content="0; url=https://example.com/posts/my-intended-url"/>

No. Per JohnMu of Google:

No, Google won't penalize a site for having 15 redirects (or any other number).

— 🐄 John 🐄 (@JohnMu) February 21, 2021

I prefer server side URL rewrites because:

  1. I can control all of my redirects in one place, tersely.
  2. I can set the response code (301, 302, 307, 308) as desired.

One or two redirects? Fine, use meta refresh. Else, handle it on the server.

1 Like

Penalizing redirects would be a bit like the IRS sending you a bill for updating your mailing address. You have something that both organizations want; you are helping them by telling them how to get it.