Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> So, I decided to create a redirect on Nginx for each old URL, pointing to the new one. It was quite frustrating to write all those redirects…

You can use a regular expression to write a single redirect for all the posts. Something like the following could do the trick:

  location ~ ^/(home|networking|misc|tips)/(\d{4})/(\d{2})/(\d{2})/([a-zA-Z0-9-_]+)\.html {
    return 301 https://giuliomagnifico.blog/post/$2-$3-$4-$5/;
  }


Damn! I didn’t know that Nginx handles regex! Thank you. This would have saved me quite a bit of time… but I already did it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: