Combine rewrites

(Dennis Wehrmann) #1

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…

(Matthew Fay) #2

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 /
}
(Dennis Wehrmann) #3

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!

(Matthew Fay) #4

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

(Dennis Wehrmann) #5

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

1 Like