Answer the question
In order to leave comments, you need to log in
How to rewrite rewrites under nginx?
Good day.
I ask for help in rewriting rewrites under nginx.
nginx version: nginx/1.4.1
The original piece of rules from .htaccess looks like this:
RewriteRule ^images/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$ media.php?size=$1&id=$2&image=square
RewriteRule ^images/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$ media.php?size=$1&id=$2&image=normal
RewriteRule ^images/w/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$ media.php?size=$1&id=$2&image=square&t=w
RewriteRule ^images/h/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$ media.php?size=$1&id=$2&image=square&t=h
RewriteRule ^images/h/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$ media.php?size=$1&id=$2&image=normal&t=h
RewriteCond %{REQUEST_URI} /images/w/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]{3})([0-9,a-z,A-Z,-_]+)\.jpg
RewriteCond /var/www/html/_cache/norm_cache_s%1w/%2/%2%3.jpg -f
RewriteRule ^images/w/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]{3})([0-9,a-z,A-Z,-_]+)\.jpg http://host.info/_cache/norm_cache_s$1w/$2/$2$3.jpg [L]
RewriteRule ^images/w/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$ media.php?size=$1&id=$2&image=normal&t=w
location ~ "/images/w/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]{3})([0-9,a-z,A-Z,-_]+)\.jpg" {
rewrite "/images/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$" /media.php?size=$1&id=$2&image=square;
rewrite "/images/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$" /media.php?size=$1&id=$2&image=normal;
rewrite "/images/w/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$" /media.php?size=$1&id=$2&image=square&t=w;
rewrite "/images/h/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$" /media.php?size=$1&id=$2&image=square&t=h;
rewrite "/images/h/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+).jpg$" /media.php?size=$1&id=$2&image=normal&t=h;
if (!-f /var/www/_cache/norm_cache_s$1w/$2$2.$3.jpg) {
rewrite "/images/w/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]{3})([0-9,a-z,A-Z,-_]+)\.jpg" http://st.host.info/_cache/norm_cache_s$1w/$2/$2$3.jpg break;
}
try_files "/_cache/norm_cache_s$1/$2/$2$3.jpg" /index-$1_$2_$2_$3_$4.html;
}
Answer the question
In order to leave comments, you need to log in
I think the quotes are redundant. Try separating all the rules into one location and debug the first rule first, then the second, and so on.
location ~ /images/w/norm/([0-9]{2,4})/([0-9,a-z,A-Z,-_]{3})([0-9,a-z,A-Z,-_]+)\.jpg {
rewrite ^/images/([0-9]{2,4})/([0-9,a-z,A-Z,-_]+)\.jpg$ /media.php?size=$1&id=$2&image=square;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question