# Redirect 400,401,403,404,500 to main website
error_page 400 401 403 404 500 https://bestofmaineguide.com

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

# Specific redirections
if ($args ~* ^s={search_term_string}$){ rewrite ^//?$ /s-{search_term_string}/? permanent; }
if ($args ~* ^filter_by=featured$){ rewrite ^/category/activities/?$ /category/activities/filter_by-featured/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/activities/?$ /category/activities/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/activities/?$ /category/activities/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/activities/?$ /category/activities/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/activities/?$ /category/activities/filter_by-review_high/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/food/recipes/?$ /category/food/recipes/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/food/recipes/?$ /category/food/recipes/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/food/recipes/?$ /category/food/recipes/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/food/recipes/?$ /category/food/recipes/filter_by-review_high/? permanent; }
if ($args ~* ^filter_by=featured$){ rewrite ^/category/food/?$ /category/food/filter_by-featured/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/food/?$ /category/food/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/food/?$ /category/food/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/food/?$ /category/food/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/food/?$ /category/food/filter_by-review_high/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/home-garden/?$ /category/home-garden/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/home-garden/?$ /category/home-garden/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/home-garden/?$ /category/home-garden/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/home-garden/?$ /category/home-garden/filter_by-review_high/? permanent; }
if ($args ~* ^filter_by=featured$){ rewrite ^/category/maine-life/?$ /category/maine-life/filter_by-featured/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/maine-life/?$ /category/maine-life/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/maine-life/?$ /category/maine-life/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/maine-life/?$ /category/maine-life/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/maine-life/?$ /category/maine-life/filter_by-review_high/? permanent; }
if ($args ~* ^filter_by=featured$){ rewrite ^/category/tv-show/bonus-clips/?$ /category/tv-show/bonus-clips/filter_by-featured/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/tv-show/bonus-clips/?$ /category/tv-show/bonus-clips/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/tv-show/bonus-clips/?$ /category/tv-show/bonus-clips/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/tv-show/bonus-clips/?$ /category/tv-show/bonus-clips/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/tv-show/bonus-clips/?$ /category/tv-show/bonus-clips/filter_by-review_high/? permanent; }
if ($args ~* ^filter_by=featured$){ rewrite ^/category/tv-show/season-1/?$ /category/tv-show/season-1/filter_by-featured/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/tv-show/season-1/?$ /category/tv-show/season-1/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/tv-show/season-1/?$ /category/tv-show/season-1/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/tv-show/season-1/?$ /category/tv-show/season-1/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/tv-show/season-1/?$ /category/tv-show/season-1/filter_by-review_high/? permanent; }
if ($args ~* ^filter_by=featured$){ rewrite ^/category/tv-show/season-2/?$ /category/tv-show/season-2/filter_by-featured/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/tv-show/season-2/?$ /category/tv-show/season-2/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/tv-show/season-2/?$ /category/tv-show/season-2/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/tv-show/season-2/?$ /category/tv-show/season-2/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/tv-show/season-2/?$ /category/tv-show/season-2/filter_by-review_high/? permanent; }
if ($args ~* ^filter_by=featured$){ rewrite ^/category/tv-show/?$ /category/tv-show/filter_by-featured/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/tv-show/?$ /category/tv-show/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/tv-show/?$ /category/tv-show/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/tv-show/?$ /category/tv-show/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/tv-show/?$ /category/tv-show/filter_by-review_high/? permanent; }
if ($args ~* ^filter_by=featured$){ rewrite ^/category/uncategorized/?$ /category/uncategorized/filter_by-featured/? permanent; }
if ($args ~* ^filter_by=popular$){ rewrite ^/category/uncategorized/?$ /category/uncategorized/filter_by-popular/? permanent; }
if ($args ~* ^filter_by=popular7$){ rewrite ^/category/uncategorized/?$ /category/uncategorized/filter_by-popular7/? permanent; }
if ($args ~* ^filter_by=random_posts$){ rewrite ^/category/uncategorized/?$ /category/uncategorized/filter_by-random_posts/? permanent; }
if ($args ~* ^filter_by=review_high$){ rewrite ^/category/uncategorized/?$ /category/uncategorized/filter_by-review_high/? 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
