RewriteEngine on

#Make subfolders use these rules too if htaccess present----------
RewriteOptions InheritDown

#Manage directory listing
Options -Indexes

#Remove www
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
#RewriteRule ^www.kawiesh.ml/(.*)$ http://kawiesh.ml/$1 [NC, L]


#Display custom page when an error has occured---------------------
ErrorDocument 400 /resources/error.html
ErrorDocument 401 /resources/error.html
ErrorDocument 403 /resources/error.html
ErrorDocument 404 /resources/error.html
ErrorDocument 500 /resources/error.html



#Serve all pages over https except notes & radio---------------
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP:CF-Visitor} !https
RewriteCond %{HTTP_USER_AGENT} !BlackBerry [NC]
RewriteCond %{REQUEST_URI} !^/radio/
RewriteCond %{REQUEST_URI} !^/blackberry/
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


#Remove html extensions from url--------------------------------
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]


#Remove i=1 parameter from url----------------------------------
#RewriteCond %{QUERY_STRING} ^(.*)i=[^&]+(.*)$ [NC]
#RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]



RewriteCond %{QUERY_STRING} ^(.*)i=[^&]+(.*)$ [NC]
RewriteRule ^ %{REQUEST_URI}? [R=301,L,NE]

#RewriteCond %{QUERY_STRING} ^i=\d*$
#RewriteRule ^(.*)$ /$1? [R=301,L]
