# Redirect non-www to www

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

# Specific redirections
if ($args ~* ^category=243$){ rewrite ^/treatment/?$ /treatment/category-243/? permanent; }
if ($args ~* ^category=260$){ rewrite ^/treatment/?$ /treatment/category-260/? permanent; }
if ($args ~* ^category=629$){ rewrite ^/treatment/?$ /treatment/category-629/? permanent; }
if ($args ~* ^hand_piece=264&item_id=4045$){ rewrite ^/before_and_after/?$ /before_and_after/hand_piece-264-item_id-4045/? permanent; }
if ($args ~* ^hand_piece=218&item_id=4716$){ rewrite ^/before_and_after/?$ /before_and_after/hand_piece-218-item_id-4716/? permanent; }
if ($args ~* ^hand_piece=269&item_id=4109$){ rewrite ^/before_and_after/?$ /before_and_after/hand_piece-269-item_id-4109/? permanent; }
if ($args ~* ^hand_piece=264&item_id=4406$){ rewrite ^/before_and_after/?$ /before_and_after/hand_piece-264-item_id-4406/? permanent; }
if ($args ~* ^category=797$){ rewrite ^/en-uk/treatment/?$ /en-uk/treatment/category-797/? permanent; }
if ($args ~* ^category=799$){ rewrite ^/en-uk/treatment/?$ /en-uk/treatment/category-799/? permanent; }
if ($args ~* ^category=798$){ rewrite ^/us/treatment/?$ /us/treatment/category-798/? permanent; }
if ($args ~* ^category=800$){ rewrite ^/us/treatment/?$ /us/treatment/category-800/? permanent; }
if ($args ~* ^category=804$){ rewrite ^/us/treatment/?$ /us/treatment/category-804/? permanent; }
if ($args ~* ^treatments=774$){ rewrite ^/us/before_and_after/?$ /us/before_and_after/treatments-774/? permanent; }
if ($args ~* ^treatments=790&item_id=4131$){ rewrite ^/us/before_and_after/?$ /us/before_and_after/treatments-790-item_id-4131/? permanent; }
if ($args ~* ^treatments=782$){ rewrite ^/us/before_and_after/?$ /us/before_and_after/treatments-782/? 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
