Many thanks
- Code: Select all
RewriteEngine On
# This simulates query params passed to img files.
# looks for a pre-created image. Any missing file is regenerated.
# if query present and file exists, redirect to correct filename (with no query)
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{REQUEST_FILENAME}-%{QUERY_STRING} -f
RewriteRule ^(.*)$ %{REQUEST_FILENAME}-%{QUERY_STRING}? [L]
# if query string is present and file does not exist, generate
# rewriteCond here == only generating files with queries, as opposed to all missing files
RewriteCond %{QUERY_STRING} !^$
RewriteRule ^(.*/)*(.*)$ /path/to/generator.php?%{QUERY_STRING}&file=$2&dir=$1 [L]
# if made it here == serve as usual
Would it be possible to combine to two blocks into one by skipping a rewrite? As the script is effectively runs twice (because it redirects to same folder), does the second time count as a sub-request, which can be skipped with a [NS] flag?