# 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]

# Prevent scraping from archive for free demo
RewriteCond %{HTTP_USER_AGENT} (ia_archiver) [NC]
RewriteRule . - [F,L]

# Specific redirections
RewriteRule ^index\.html$ / [L,R=301]
RewriteCond %{QUERY_STRING} ^mid=1117005&cid=0&url=http\%3A\%2F\%2Ftcb-bank\.com\.tw$
RewriteRule ^go-c-1117005\.html$ go-c-1117005_mid-1117005-cid-0-url-http-tcb-bank_com_tw [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^mid=1117005&cid=-2001&url=http\%3A\%2F\%2Ftcb-bank\.com\.tw$
RewriteRule ^go-c--2001\.html$ go-c--2001_mid-1117005-cid--2001-url-http-tcb-bank_com_tw [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^mid=800919&cid=0&url=http\%3A\%2F\%2Forder\.toppers\.com$
RewriteRule ^go-c-800919\.html$ go-c-800919_mid-800919-cid-0-url-http-order_toppers_com [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^mid=800919&cid=-2001&url=http\%3A\%2F\%2Forder\.toppers\.com$
RewriteRule ^go-c--2001\.html$ go-c--2001_mid-800919-cid--2001-url-http-order_toppers_com [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^mid=1423930&cid=0&url=https\%3A\%2F\%2Felleair\.tw\%2F$
RewriteRule ^go-c-1423930\.html$ go-c-1423930_mid-1423930-cid-0-url-https-elleair_tw [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^mid=1423930&cid=-2001&url=https\%3A\%2F\%2Felleair\.tw\%2F$
RewriteRule ^go-c--2001\.html$ go-c--2001_mid-1423930-cid--2001-url-https-elleair_tw [L,R=301,QSD]

# Create pretty URLs
DirectorySlash Off

RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
RewriteRule ^ %1 [NC,L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} (.*)/$
RewriteRule ^(.*)/$ $1 [NC,L,R=301]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [NC,L]
# 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
