<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteCond %{HTTP_HOST} ^www\.calorate\.com$ [NC]
  RewriteRule ^ https://calorate.net%{REQUEST_URI} [R=301,L,NE]

  RewriteRule ^en/?$ / [R=301,L]
  RewriteRule ^en/(.+)$ /$1 [R=301,L]

  RewriteRule ^calories/?$ /calorie [R=301,L]
  RewriteRule ^calories/topics/?$ /calorie/topics [R=301,L]
  RewriteRule ^calories/topics/([^/]+)/?$ /calorie/topics/$1 [R=301,L]
  RewriteRule ^calories/([^/]+)/?$ /calorie/$1 [R=301,L]

  RewriteRule ^(tr|es|ru|de|fr|ko|ja|pt|it)/calories/?$ /$1/calorie [R=301,L]
  RewriteRule ^(tr|es|ru|de|fr|ko|ja|pt|it)/calories/topics/?$ /$1/calorie/topics [R=301,L]
  RewriteRule ^(tr|es|ru|de|fr|ko|ja|pt|it)/calories/topics/([^/]+)/?$ /$1/calorie/topics/$2 [R=301,L]
  RewriteRule ^(tr|es|ru|de|fr|ko|ja|pt|it)/calories/([^/]+)/?$ /$1/calorie/$2 [R=301,L]

  RewriteRule ^diets/keto-diet/?$ /diets/ketogenic-diet [R=301,L]
  RewriteRule ^(tr|es|ru|de|fr|ko|ja|pt|it)/diets/keto-diet/?$ /$1/diets/ketogenic-diet [R=301,L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !^/$ [NC]
  RewriteCond %{REQUEST_URI} !^/(tr|es|ru|de|fr|ko|ja|pt|it)/?$ [NC]
  RewriteCond %{REQUEST_URI} !^/((tr|es|ru|de|fr|ko|ja|pt|it)/)?(privacy-policy|terms-of-use|about|editorial-policy|reset-password)/?$ [NC]
  RewriteCond %{REQUEST_URI} !^/((tr|es|ru|de|fr|ko|ja|pt|it)/)?(calorie|diets|calculators)(/[^/]+)?/?$ [NC]
  RewriteCond %{REQUEST_URI} !^/((tr|es|ru|de|fr|ko|ja|pt|it)/)?calorie/topics(/[^/]+)?/?$ [NC]
  RewriteCond %{REQUEST_URI} !^/manager/(login|reset-password|dashboard|change-password|profile-settings|exemptions|foods|exercise-templates|parameters)/?$ [NC]
  RewriteRule ^ - [R=404,L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ index.html [L]
</IfModule>

<IfModule mod_setenvif.c>
  SetEnvIfNoCase Query_String ".+" HAS_QUERY_STRING=1
</IfModule>

<IfModule mod_headers.c>
  Header set X-Powered-By "Calorate"
  Header set X-Robots-Tag "noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1" env=HAS_QUERY_STRING
</IfModule>
