Answer the question
In order to leave comments, you need to log in
How to make a redirect to a file in .htaccess, taking into account the query string?
Hello! The essence of the task is to return reduced versions of pictures, if they exist, and if not, then redirect the request to a script that will make a reduced version.
How it works:
1. The /original folder contains original images, for example /original/1.jpg
2. To reduce images, it is suggested to use the /resized/ prefix and GET parameters. Like this: /resized/original/1.jpg?w=100&h=100
3. It is supposed that if the file /resized/original/1_100_100.jpg exists, then give it away, if it does not exist, then redirect to /resizer.php (RewriteRule ^(.*)$ /resizer.php?path=$1 [NC,L,QSA])
Now the rezised folder contains the following .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /resizer.php?path=$1 [NC,L,QSA]
</IfModule>
Answer the question
In order to leave comments, you need to log in
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond &%{QUERY_STRING} ^(?=.*&w=(\d+))(?=.*&h=(\d+))
RewriteCond %{DOCUMENT_ROOT}/resized/$1_%1_%2.$2 -f
RewriteRule ^(original/.+)\.(.+) /resized/$1_%1_%2.$2 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /resizer.php?path=$1 [L,QSA]
</IfModule>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question