Too much repetition in this conditional. How about simply 2 conditions:

1. If there's a previous page, generate `link rel=prev`
2. If there's a next page, generate `link rel=next`