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

# Specific redirections
if ($args ~* ^s=\%7Bsearch_term_string\%7D$){ rewrite ^//?$ /s-{search_term_string}/? permanent; }
if ($args ~* ^orderby=date&order=ASC$){ rewrite ^/category/%D8%A7%D9%84%D8%B9%D8%A7%D8%A8-%D8%A7%D9%86%D8%AF%D8%B1%D9%88%D9%8A%D8%AF/%D8%A3%D9%84%D8%BA%D8%A7%D8%B2-%D8%A7%D9%84%D8%B9%D8%A7%D8%A8-%D8%A7%D9%86%D8%AF%D8%B1%D9%88%D9%8A%D8%AF/?$ /category/العاب-اندرويد/ألغاز-العاب-اندرويد/orderby-date-order-ASC/? permanent; }
if ($args ~* ^orderby=modified&order=DESC$){ rewrite ^/category/%D8%A7%D9%84%D8%B9%D8%A7%D8%A8-%D8%A7%D9%86%D8%AF%D8%B1%D9%88%D9%8A%D8%AF/%D8%A3%D9%84%D8%BA%D8%A7%D8%B2-%D8%A7%D9%84%D8%B9%D8%A7%D8%A8-%D8%A7%D9%86%D8%AF%D8%B1%D9%88%D9%8A%D8%AF/?$ /category/العاب-اندرويد/ألغاز-العاب-اندرويد/orderby-modified-order-DESC/? permanent; }
if ($args ~* ^orderby=date&order=ASC$){ rewrite ^/category/%D8%A7%D9%84%D8%B9%D8%A7%D8%A8-%D9%85%D9%87%D9%83%D8%B1/%D8%A7%D9%84%D9%85%D8%AD%D8%A7%D9%83%D8%A7%D8%A9-%D8%A7%D9%84%D8%B9%D8%A7%D8%A8-%D9%85%D9%87%D9%83%D8%B1/?$ /category/العاب-مهكر/المحاكاة-العاب-مهكر/orderby-date-order-ASC/? permanent; }
if ($args ~* ^orderby=date&order=ASC$){ rewrite ^/category/%D8%AA%D8%B1%D9%81%D9%8A%D9%87/?$ /category/ترفيه/orderby-date-order-ASC/? permanent; }
if ($args ~* ^orderby=modified&order=DESC$){ rewrite ^/category/%D8%AA%D8%B1%D9%81%D9%8A%D9%87/?$ /category/ترفيه/orderby-modified-order-DESC/? permanent; }
if ($args ~* ^orderby=modified&order=DESC$){ rewrite ^/category/temp-mail/?$ /category/temp-mail/orderby-modified-order-DESC/? 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
