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

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

# Specific redirections
rewrite ^/programme/side-events/environmental-and-social-impact-assessment-what-is-its-impact-and-effectiveness-for-the-poor-in-african-cities-the-environmental-assessment-process-can-contributes-to-sustainable-development-throug$ /files/e-development-throug_p3v3nm6867ryxpgkmny0m4/? permanent;
rewrite ^/programme/listen-to-cities-room-local-action/the-city-and-the-territory-the-role-of-intermediary-cities-and-the-territorial-approach-to-local-development-for-achieving-the-sdgs-and-the-new-urban-agenda$ /files/the-new-urban-agenda_opj6f8pna7ufp7dy722ip7/? permanent;
rewrite ^/programme/networking-events/urban-transformation-in-russian-cities-in-times-of-mega-events-and-economic-transition-learning-from-the-adoption-of-the-new-urban-agenda-and-the-implementation-of-the-sdg11$ /files/ntation-of-the-sdg11_4gbp7te6v0fpguc6jytsmr/? permanent;
rewrite ^/programme/listen-to-cities-room-local-action/towards-social-and-urban-integration-of-slums-and-precarious-settlements-implementing-the-law-for-fair-access-to-habitat-and-new-urban-agenda-in-the-province-of-buenos-aires$ /files/ince-of-buenos-aires_fu2esv8vh8ztts6sxqfqjp/? permanent;
rewrite ^/programme/one-un-room/physical-inactivity-and-rising-non-communicable-diseases-how-creating-space-for-sport-can-support-the-implementation-of-the-new-urban-agenda-and-drive-socioeconomic-development-in-asia-pacific$ /files/ment-in-asia-pacific_apd8h0p2rnpcjyjkuo2mdt/? permanent;
rewrite ^/programme/side-events/citizen-city-collaboration-in-contested-spaces-from-theory-to-practice-real-world-examples-for-implementing-the-new-urban-agenda-at-three-scales-the-neighborhood-of-kibera-the-city-of-dhaka-and-t$ /files/-city-of-dhaka-and-t_6f3kwbp0yk38tceoa6tg23/? permanent;
rewrite ^/programme/side-events/national-policies-for-strengthening-the-role-and-resilience-of-local-authorities-towards-implementing-global-development-frameworks-and-local-economic-growth-implementing-the-new-urban-agenda$ /files/the-new-urban-agenda_8ozc7mived0aktpj2ems20/? permanent;
rewrite ^/programme/listen-to-cities-room-local-action/turning-urban-shrinkage-into-opportunities-for-sustainable-redevelopment-reflection-from-the-experience-of-the-city-of-saint-etienne-france-and-invitation-to-an-international-dialogue$ /files/ternational-dialogue_0p5g65nq5nt8igfdkuah4y/? permanent;
rewrite ^/programme/networking-events/les-dispositifs-pratiques-et-outils-de-gouvernance-locale-participative-et-dinclusion-sociale-pour-promouvoir-les-droits-a-la-cites-et-operationnaliser-le-nouvel-agenda-urbain-et-les-objectifs-de-de$ /files/-les-objectifs-de-de_poo8za7s87bz2jpfbkompb/? permanent;
rewrite ^/programme/side-events/delivering-priority-infrastructure-improved-services-and-planned-cities-for-urban-management-an-inclusive-approach-to-implementing-the-new-urban-agenda-and-achieving-the-sdgs$ /files/d-achieving-the-sdgs_c50hyssmmgawezv8dtddby/? permanent;
rewrite ^/programme/networking-events/dealing-with-rapid-urbanisation-tools-and-experiences-the-rapid-rates-and-scale-of-urbanisation-around-the-world-are-a-core-focus-for-all-involved-in-creating-sustainable-cities-and-communities-whi$ /files/-and-communities-whi_4rd3u4emvn7emff6cbtaii/? permanent;
rewrite ^/programme/side-events/a-multidimensional-view-of-the-implementation-of-the-new-world-urban-agenda-from-the-micro-territory-and-community-sustainability-in-neighborhoods-of-informal-origin-case-studies-san-agustin-neighb$ /files/s-san-agustin-neighb_0fnaai6gind0osujhjs4s4/? permanent;
rewrite ^/programme/side-events/implementation-of-the-fukuoka-method-landfill-and-solid-waste-management-system-a-low-cost-and-environmentally-sustainable-solution-to-tackle-solid-waste-issues-in-the-growing-urban-sector$ /files/growing-urban-sector_soxmypf5uwrza2aoqygw5g/? permanent;
rewrite ^/programme/side-events/managing-natural-disaster-risks-in-cities-tomorrow-how-can-multilateral-and-bilateral-financing-institutions-contribute-to-urban-resilience-through-financing-knowledge-and-technical-expertise$ /files/-technical-expertise_vejv68qxoh7yx3gj5k378q/? permanent;
rewrite ^/programme/side-events/the-role-of-local-governments-in-the-implementation-of-the-new-urban-agenda-and-ensuring-sustainable-urban-development-lessons-learned-from-the-big-six-cities-of-the-punjab-pakistan$ /files/-the-punjab-pakistan_7pi3habsnkdhimnsvd0s6i/? permanent;
rewrite ^/programme/networking-events/measurement-index-and-dashboards-for-measurement-of-progress-and-success-towards-achieving-sustainable-development-goals-in-the-establishment-of-smart-sustainable-cities$ /files/t-sustainable-cities_x2mke35m3yuy4r43e7tum0/? permanent;
if ($args ~* ^d=13$){ rewrite ^/un-habitat/?$ /un-habitat/d-13/? permanent; }
if ($args ~* ^d=13$){ rewrite ^/programme/thematic-itineraries/?$ /programme/thematic-itineraries/d-13/? 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
