# Add a trailing slash (/) to a URL
rewrite ^([^.]*[^/])$ $1/ permanent;

# Specific redirections
if ($args ~* ^per_page=9$){ rewrite ^/shop/?$ /shop/per_page-9/? permanent; }
if ($args ~* ^per_page=12$){ rewrite ^/shop/?$ /shop/per_page-12/? permanent; }
if ($args ~* ^per_page=18$){ rewrite ^/shop/?$ /shop/per_page-18/? permanent; }
if ($args ~* ^per_page=24$){ rewrite ^/shop/?$ /shop/per_page-24/? permanent; }
if ($args ~* ^shop_view=grid&per_row=2$){ rewrite ^/shop/?$ /shop/shop_view-grid-per_row-2/? permanent; }
if ($args ~* ^shop_view=grid&per_row=3$){ rewrite ^/shop/?$ /shop/shop_view-grid-per_row-3/? permanent; }
if ($args ~* ^shop_view=grid&per_row=4$){ rewrite ^/shop/?$ /shop/shop_view-grid-per_row-4/? permanent; }
if ($args ~* ^per_page=9$){ rewrite ^/sza-shirt/?$ /sza-shirt/per_page-9/? permanent; }
if ($args ~* ^per_page=12$){ rewrite ^/sza-shirt/?$ /sza-shirt/per_page-12/? permanent; }
if ($args ~* ^per_page=18$){ rewrite ^/sza-shirt/?$ /sza-shirt/per_page-18/? permanent; }
if ($args ~* ^per_page=24$){ rewrite ^/sza-shirt/?$ /sza-shirt/per_page-24/? permanent; }
if ($args ~* ^shop_view=grid&per_row=2$){ rewrite ^/sza-shirt/?$ /sza-shirt/shop_view-grid-per_row-2/? permanent; }
if ($args ~* ^shop_view=grid&per_row=3$){ rewrite ^/sza-shirt/?$ /sza-shirt/shop_view-grid-per_row-3/? permanent; }
if ($args ~* ^shop_view=grid&per_row=4$){ rewrite ^/sza-shirt/?$ /sza-shirt/shop_view-grid-per_row-4/? permanent; }
if ($args ~* ^per_page=9$){ rewrite ^/sza-hoodie/?$ /sza-hoodie/per_page-9/? permanent; }
if ($args ~* ^per_page=12$){ rewrite ^/sza-hoodie/?$ /sza-hoodie/per_page-12/? permanent; }
if ($args ~* ^per_page=18$){ rewrite ^/sza-hoodie/?$ /sza-hoodie/per_page-18/? permanent; }
if ($args ~* ^per_page=24$){ rewrite ^/sza-hoodie/?$ /sza-hoodie/per_page-24/? permanent; }
if ($args ~* ^shop_view=grid&per_row=2$){ rewrite ^/sza-hoodie/?$ /sza-hoodie/shop_view-grid-per_row-2/? permanent; }
if ($args ~* ^shop_view=grid&per_row=3$){ rewrite ^/sza-hoodie/?$ /sza-hoodie/shop_view-grid-per_row-3/? permanent; }
if ($args ~* ^shop_view=grid&per_row=4$){ rewrite ^/sza-hoodie/?$ /sza-hoodie/shop_view-grid-per_row-4/? permanent; }

# Create pretty URLs
rewrite ^/([^/]+)/$ /$1.html last;
rewrite ^/([^/]+)/([^/]+)/$ /$1/$2.html last;
rewrite ^/([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3.html last;
rewrite ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3/$4.html last;
rewrite ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3/$4/$5.html last;
rewrite ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3/$4/$5/$6.html last;
rewrite ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3/$4/$5/$6/$7.html last;
rewrite ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3/$4/$5/$6/$7/$8.html last;
rewrite ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3/$4/$5/$6/$7/$8/$9.html last;
rewrite ^/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3/$4/$5/$6/$7/$8/$9/$10.html last;
# End: Create pretty URLs

# Redirect all extensions to html
if ($is_args = ''){
	rewrite ^([^.]*)\.shtml$ $1.html permanent;
	rewrite ^([^.]*)\.phtml$ $1.html permanent;
	rewrite ^([^.]*)\.jhtml$ $1.html permanent;
	rewrite ^([^.]*)\.htm$ $1.html permanent;
	rewrite ^([^.]*)\.php$ $1.html permanent;
	rewrite ^([^.]*)\.aspx$ $1.html permanent;
	rewrite ^([^.]*)\.asp$ $1.html permanent;
	rewrite ^([^.]*)\.jsp$ $1.html permanent;
	rewrite ^([^.]*)\.apk$ $1.html permanent;
}
# End: Redirect all extensions to html
