# Redirect non-www to www

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

# Specific redirections
if ($args ~* ^rt=78921$){ rewrite ^/booking2hotels_book/?$ /booking2hotels_book/rt-78921/? permanent; }
if ($args ~* ^rt=78922$){ rewrite ^/booking2hotels_book/?$ /booking2hotels_book/rt-78922/? permanent; }
if ($args ~* ^rt=79341$){ rewrite ^/booking2hotels_book/?$ /booking2hotels_book/rt-79341/? permanent; }
if ($args ~* ^rt=78962$){ rewrite ^/booking2hotels_book/?$ /booking2hotels_book/rt-78962/? permanent; }
if ($args ~* ^q=heritage-route$){ rewrite ^/attraction_type/attraction/?$ /attraction_type/attraction/q-heritage-route/? permanent; }
if ($args ~* ^q=heritage-route$){ rewrite ^/attraction_type/sanah-siam/?$ /attraction_type/sanah-siam/q-heritage-route/? permanent; }
if ($args ~* ^q=cbd-route$){ rewrite ^/attraction_type/attraction/?$ /attraction_type/attraction/q-cbd-route/? permanent; }
if ($args ~* ^q=cbd-route$){ rewrite ^/attraction_type/sanah-siam/?$ /attraction_type/sanah-siam/q-cbd-route/? permanent; }
if ($args ~* ^q=entertainment-route$){ rewrite ^/attraction_type/attraction/?$ /attraction_type/attraction/q-entertainment-route/? permanent; }
if ($args ~* ^q=entertainment-route$){ rewrite ^/attraction_type/sanah-siam/?$ /attraction_type/sanah-siam/q-entertainment-route/? permanent; }
if ($args ~* ^q=shopping-route$){ rewrite ^/attraction_type/attraction/?$ /attraction_type/attraction/q-shopping-route/? permanent; }
if ($args ~* ^q=shopping-route$){ rewrite ^/attraction_type/sanah-siam/?$ /attraction_type/sanah-siam/q-shopping-route/? 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
