Combine rewrites

Hello, can anybody help me combining these two rewrites?

rewrite {
    to {path} {path}/ /
}

and

rewrite {
     regexp ^\/wp-content\/uploads\/edd\/.*?\/.*?\.jpg$
     to /
}

Any help would be much appreciated, I cannot figure this out somehow…

Because both rewrites are scoped to / (i.e. all requests), the top one wins every time. Only one rewrite executes for each request. The regex is an additional check to the (unspecified) base path.

The matcher picks the rewrite with the longest matching base path, though.

Ditch the regex, it’s slow and completely unnecessary.

rewrite {
  to {path} {path}/ /
}

rewrite /wp-content/uploads/edd/2019 {
  # Uncomment this if it's absolutely necessary
  # only to rewrite this index and not anything below it:
  # if {path} is /wp-content/uploads/edd/2019
  to /
}

Aha, thanks for the insight. I have updated my regex in the original question, forgot the most important parts. However, I replaced it with /wp-content/uploads/edd which works just fine – Thanks!

Just to clarify - you didn’t update it to regexp /wp-content/uploads/edd, did you?

no, I replaced my original regex ^\/wp-content\/uploads\/edd\/.*?\/.*?\.jpg$ with rewrite /wp-content/uploads/edd { ...

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.