5

I need to catch if my urls contain a small substr, keep the url as it is and rewrite only that small part, how can I accomplish this?

For example:

http://foobar.com/foo-bar-substrtocatch-baz 

should become

http://foobar.com/foo-bar-changedsubstr-baz

Thanks in advance...

ngw
  • 1,261
  • 3
  • 13
  • 15

1 Answers1

8
rewrite    ^(.*)substrtocatch(.*)$    $1changedsubstr$2;
cnst
  • 13,848
  • 9
  • 54
  • 76
  • Wouldn't `return` be better to inform SEO and robots of the 301? – Zac Grierson Jul 03 '17 at 21:35
  • 1
    @ZacGrierson It depends on what you want to do; if a 301 is required, just use the `permanent` flag as per http://nginx.org/r/rewrite – cnst Jul 05 '17 at 03:41