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

# Specific redirections
if ($args ~* ^dm_device=desktop&_rdr$){ rewrite ^//?$ /dm_device-desktop-_rdr/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^//?$ /dm_device-desktop/? permanent; }
if ($args ~* ^dm_device=desktop&_rdr$){ rewrite ^/contact-macs-tree-service-middleburg-fl/?$ /contact-macs-tree-service-middleburg-fl_dm_device-desktop-_rdr/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^/contact-macs-tree-service-middleburg-fl/?$ /contact-macs-tree-service-middleburg-fl_dm_device-desktop/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^/crane-and-bucket-truck-service/?$ /crane-and-bucket-truck-service_dm_device-desktop/? permanent; }
if ($args ~* ^dm_device=desktop&_rdr$){ rewrite ^/middleburg-fl-land-clearing/?$ /middleburg-fl-land-clearing_dm_device-desktop-_rdr/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^/middleburg-fl-land-clearing/?$ /middleburg-fl-land-clearing_dm_device-desktop/? permanent; }
if ($args ~* ^dm_device=desktop&_rdr$){ rewrite ^/middleburg-fl-pruning/?$ /middleburg-fl-pruning_dm_device-desktop-_rdr/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^/middleburg-fl-pruning/?$ /middleburg-fl-pruning_dm_device-desktop/? permanent; }
if ($args ~* ^dm_device=desktop&_rdr$){ rewrite ^/middleburg-fl-stump-grinding/?$ /middleburg-fl-stump-grinding_dm_device-desktop-_rdr/? permanent; }
if ($args ~* ^dm_device=desktop&_rdr$){ rewrite ^/middleburg-fl-testimonials/?$ /middleburg-fl-testimonials_dm_device-desktop-_rdr/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^/middleburg-fl-testimonials/?$ /middleburg-fl-testimonials_dm_device-desktop/? permanent; }
if ($args ~* ^dm_device=desktop&_rdr$){ rewrite ^/middleburg-fl-tree-removal/?$ /middleburg-fl-tree-removal_dm_device-desktop-_rdr/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^/middleburg-fl-tree-removal/?$ /middleburg-fl-tree-removal_dm_device-desktop/? permanent; }
if ($args ~* ^dm_device=desktop&_rdr$){ rewrite ^/middleburg-fl-tree-service/?$ /middleburg-fl-tree-service_dm_device-desktop-_rdr/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^/middleburg-fl-tree-service/?$ /middleburg-fl-tree-service_dm_device-desktop/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^/index\.html$ /index_dm_device-desktop/? permanent; }
if ($args ~* ^dm_device=desktop$){ rewrite ^/middleburg-fl-stump-grinding\.html$ /middleburg-fl-stump-grinding_dm_device-desktop/? 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
