I am trying to build a rewrite rule that allows to match a request to different files (same name, but different extension), in particular, the rewrite url should first check if a file exists with one extension, if not go on to the second and so on.
I am currently using this rule:
- Code: Select all
RewriteRule ^([^.]+)/$ cache/$1.html
RewriteRule ^([^.]+)$ cache/$1.html
The above rule matches requests such as /test/test (or with ending slash) to the appropriate file in the cache folder, including subfolders.
However I'm not able to add the appropriate rule to let it check/rewrite to the next possible extension, such as jpg. Here, with the same request and if the html file does not exist, the rule should try to match the request to a jpg file:
- Code: Select all
RewriteRule ^([^.]+)$ cache/$1.jpg
Since the request has already been rewritten by the first rule, this second rule never applies and hence the jpg file is not found, even though it exists.
What could I do to solve this? Should I rewrite the request back prior to checking for the jpg file? Or is there a better way to solve this?
Thanks