Redirects using placeholder but the last placeholder has .html that I want to remove

I have this in the config:

[[redirects]]
  from = "/:cat/:year/:month/:day/:slug.html"
  to = "/:year/:slug/"
  status = 301

An example is:

https://candland.net/rails/2020/10/16/rails-json-serialized-fields-validation.html
https://candland.net/2020/rails-json-serialized-fields-validation/

It half works and redirects to /2020/:slug/ so the slug placeholder isn’t getting parsed out.

I haven’t moved DNS over yet. The site is: Rails JSON Serialized Fields - Validations | candland.net

Is what I’m trying to do possible in some way?

Thanks!

Hey they, @candland :wave:

Looks like this thread has been quiet for a few days since you opened this. Sorry about that!

Are you still having this issue? If so, what have you tried in the past week to debug this? Have you read our troubleshooting redirects guide? Let us know!

Hi @hillary. I looked at that troubleshooting guide… didn’t see anything related to removing the .html extension in the redirects.

The deploy says it processed the rule.

But, it’s doing the same thing. It can parse the :year value but not the :slug value.

Hey there! Can you try dropping the .html suffix in your to rule?

Hi @Scott,

I didn’t have .html in my to rule, rather in the from rule. Removed it just to test.

The rule now:

[[redirects]]
  from = "/:cat/:year/:month/:day/:slug"
  to = "/:year/:slug/"
  status = 301

Now the slug is replaced, but it has .html which is the main part I’m trying to remove with this rule.

Now https://candland-net.netlify.app/rails/2020/10/16/rails-json-serialized-fields-validation.html
goes here https://candland-net.netlify.app/2020/rails-json-serialized-fields-validation.html/.

Is there a way to get the rails-json-serialized-fields-validation part of the URL without the .html? Or a way to remove the .html in the to part of the rule?

Thanks!

Dusty

Hey! You’re right – I meant the from condition’s .html.

Yeah, if you navigate to https://candland-net.netlify.app/2020/rails-json-serialized-fields-validation/ then that’ll strip .html :wink:

We serve the content on both URLs, for all sites. With some clever headers which we set as default, it doesn’t appear as duplicated content.

This is completely untested but you could maybe try:

    [[redirects]]
      from = "/:cat/:year/:month/:day/:slug.:extension"
      to = "/:year/:slug/"
      status = 301

Tried with :extension, but no luck. Seems like maybe it’s not possible with the current system?

Drats. In which case, we won’t be able to redirect and strip the extension!

1 Like