# 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} ^sortBy=popular&sortDirection=Desc&price=200000&price=300000$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-price-200000-price-300000 [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&price=300000&price=500000$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-price-300000-price-500000 [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&price=500000&price=700000$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-price-500000-price-700000 [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&price=700000&price=1000000$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-price-700000-price-1000000 [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&price=1000000&price=1500000$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-price-1000000-price-1500000 [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&price=1500000&price=20000000$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-price-1500000-price-20000000 [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=sports$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-sports [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=street$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-street [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=cruiser$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-cruiser [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=commuter$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-commuter [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=super$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-super [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=cafeRacer$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-cafeRacer [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=sportsTouring$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-sportsTouring [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=adventureTouring$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-adventureTouring [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=dirt$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-dirt [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=electric$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-electric [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=scooter$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-scooter [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=maxiScooter$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-maxiScooter [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&fuelType=electric$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-fuelType-electric [L,R=301,QSD]
RewriteCond %{QUERY_STRING} ^sortBy=popular&sortDirection=Desc&bodyType=scooter&fuelType=electric$
RewriteRule ^new-bikes$ new-bikes_sortBy-popular-sortDirection-Desc-bodyType-scooter-fuelType-electric [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
