# Redirect non-www to www

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

# Specific redirections
if ($args ~* ^s=\%C3\%BArsula$){ rewrite ^//?$ /s-úrsula/? permanent; }
if ($args ~* ^s=cb\+canarias$){ rewrite ^//?$ /s-cb-canarias/? permanent; }
if ($args ~* ^lang=en$){ rewrite ^/aulavirtual/?$ /aulavirtual/lang-en/? permanent; }
if ($args ~* ^lang=es$){ rewrite ^/aulavirtual/?$ /aulavirtual/lang-es/? permanent; }
if ($args ~* ^s=\%C3\%BArsula$){ rewrite ^/page/2/?$ /page/2/s-úrsula/? permanent; }
if ($args ~* ^s=\%C3\%BArsula$){ rewrite ^/page/3/?$ /page/3/s-úrsula/? permanent; }
if ($args ~* ^s=\%C3\%BArsula$){ rewrite ^/page/4/?$ /page/4/s-úrsula/? permanent; }
if ($args ~* ^s=cb\+canarias$){ rewrite ^/page/2/?$ /page/2/s-cb-canarias/? permanent; }
if ($args ~* ^lang=en$){ rewrite ^/aulavirtual/login/forgot_password\.php$ /aulavirtual/login/forgot_password_lang-en/? permanent; }
if ($args ~* ^lang=es$){ rewrite ^/aulavirtual/login/forgot_password\.php$ /aulavirtual/login/forgot_password_lang-es/? permanent; }
if ($args ~* ^attachment_id=463$){ rewrite ^//?$ /attachment_id-463/? permanent; }
if ($args ~* ^attachment_id=2146$){ rewrite ^//?$ /attachment_id-2146/? permanent; }
if ($args ~* ^attachment_id=2346$){ rewrite ^//?$ /attachment_id-2346/? permanent; }
if ($args ~* ^attachment_id=2347$){ rewrite ^//?$ /attachment_id-2347/? permanent; }
if ($args ~* ^attachment_id=2348$){ rewrite ^//?$ /attachment_id-2348/? permanent; }
if ($args ~* ^attachment_id=2489$){ rewrite ^//?$ /attachment_id-2489/? permanent; }
if ($args ~* ^attachment_id=2660$){ rewrite ^//?$ /attachment_id-2660/? permanent; }
if ($args ~* ^attachment_id=2667$){ rewrite ^//?$ /attachment_id-2667/? permanent; }
if ($args ~* ^attachment_id=267$){ rewrite ^//?$ /attachment_id-267/? permanent; }
if ($args ~* ^attachment_id=269$){ rewrite ^//?$ /attachment_id-269/? permanent; }
if ($args ~* ^attachment_id=2722$){ rewrite ^//?$ /attachment_id-2722/? permanent; }
if ($args ~* ^attachment_id=3049$){ rewrite ^//?$ /attachment_id-3049/? permanent; }
if ($args ~* ^attachment_id=3101$){ rewrite ^//?$ /attachment_id-3101/? permanent; }
if ($args ~* ^attachment_id=773$){ rewrite ^//?$ /attachment_id-773/? permanent; }
if ($args ~* ^attachment_id=774$){ rewrite ^//?$ /attachment_id-774/? permanent; }
if ($args ~* ^s=\%7Bsearch_term_string\%7D$){ rewrite ^//?$ /s-{search_term_string}/? permanent; }
if ($args ~* ^post_type=attachment$){ rewrite ^/category/publicaciones/?$ /category/publicaciones/post_type-attachment/? permanent; }
rewrite ^/search/cb\scanarias$ /search/cbcanarias/? permanent;
if ($args ~* ^post_type=event$){ rewrite ^/tag/2015/?$ /tag/2015/post_type-event/? permanent; }
if ($args ~* ^post_type=event$){ rewrite ^/tag/gym/?$ /tag/gym/post_type-event/? permanent; }
if ($args ~* ^post_type=event$){ rewrite ^/tag/is-coming/?$ /tag/is-coming/post_type-event/? permanent; }
if ($args ~* ^post_type=event$){ rewrite ^/tag/summer/?$ /tag/summer/post_type-event/? 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
