# invoke rewrite engine
RewriteEngine On
RewriteBase /

Options -Indexes
<IfModule mod_negotiation.c>
	Options -MultiViews
</IfModule>

# Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# Add a trailing slash (/) to a URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.[A-Za-z0-9]*$
RewriteRule .*[^/]$ %{REQUEST_URI}/ [L,R=301]

# Specific redirections
RewriteRule ^index\.html$ / [L,R=301]
RewriteCond %{QUERY_STRING} ^s=\%C3\%BArsula$
RewriteRule ^/?$ s-úrsula/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^s=cb\+canarias$
RewriteRule ^/?$ s-cb-canarias/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^lang=en$
RewriteRule ^aulavirtual/?$ aulavirtual/lang-en/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^lang=es$
RewriteRule ^aulavirtual/?$ aulavirtual/lang-es/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^s=\%C3\%BArsula$
RewriteRule ^page/2/?$ page/2/s-úrsula/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^s=\%C3\%BArsula$
RewriteRule ^page/3/?$ page/3/s-úrsula/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^s=\%C3\%BArsula$
RewriteRule ^page/4/?$ page/4/s-úrsula/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^s=cb\+canarias$
RewriteRule ^page/2/?$ page/2/s-cb-canarias/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^lang=en$
RewriteRule ^aulavirtual/login/forgot_password\.php$ aulavirtual/login/forgot_password_lang-en/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^lang=es$
RewriteRule ^aulavirtual/login/forgot_password\.php$ aulavirtual/login/forgot_password_lang-es/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=463$
RewriteRule ^/?$ attachment_id-463/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=2146$
RewriteRule ^/?$ attachment_id-2146/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=2346$
RewriteRule ^/?$ attachment_id-2346/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=2347$
RewriteRule ^/?$ attachment_id-2347/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=2348$
RewriteRule ^/?$ attachment_id-2348/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=2489$
RewriteRule ^/?$ attachment_id-2489/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=2660$
RewriteRule ^/?$ attachment_id-2660/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=2667$
RewriteRule ^/?$ attachment_id-2667/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=267$
RewriteRule ^/?$ attachment_id-267/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=269$
RewriteRule ^/?$ attachment_id-269/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=2722$
RewriteRule ^/?$ attachment_id-2722/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=3049$
RewriteRule ^/?$ attachment_id-3049/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=3101$
RewriteRule ^/?$ attachment_id-3101/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=773$
RewriteRule ^/?$ attachment_id-773/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^attachment_id=774$
RewriteRule ^/?$ attachment_id-774/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^s=\%7Bsearch_term_string\%7D$
RewriteRule ^/?$ s-{search_term_string}/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^post_type=attachment$
RewriteRule ^category/publicaciones/?$ category/publicaciones/post_type-attachment/ [L,R=301,QSD]
RewriteRule ^search/cb\scanarias$ search/cbcanarias/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^post_type=event$
RewriteRule ^tag/2015/?$ tag/2015/post_type-event/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^post_type=event$
RewriteRule ^tag/gym/?$ tag/gym/post_type-event/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^post_type=event$
RewriteRule ^tag/is-coming/?$ tag/is-coming/post_type-event/ [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^post_type=event$
RewriteRule ^tag/summer/?$ tag/summer/post_type-event/ [L,R=301,QSD]

# Create pretty URLs
RewriteRule ^([^/]+)/$ $1.html [S=9]
RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.html [S=8]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ $1/$2/$3.html [S=7]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ $1/$2/$3/$4.html [S=6]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ $1/$2/$3/$4/$5.html [S=5]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ $1/$2/$3/$4/$5/$6.html [S=4]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ $1/$2/$3/$4/$5/$6/$7.html [S=3]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ $1/$2/$3/$4/$5/$6/$7/$8.html [S=2]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ $1/$2/$3/$4/$5/$6/$7/$8/$9.html [S=1]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/$ $1/$2/$3/$4/$5/$6/$7/$8/$9/$10.html
# End: Create pretty URLs

# Redirect all extensions to html
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.shtml$ $1.html [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.phtml$ $1.html [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.jhtml$ $1.html [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.htm$ $1.html [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.php$ $1.html [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.aspx$ $1.html [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.asp$ $1.html [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.jsp$ $1.html [L,NC,R=301]
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.apk$ $1.html [L,NC,R=301]
# End: Redirect all extensions to html
