<IfModule mod_rewrite.c>
RewriteEngine On

    RewriteCond %{HTTP_USER_AGENT} Baiduspider [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} Sogou [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} 360Spider [NC,OR]
  RewriteCond %{HTTP_USER_AGENT} YisouSpider [NC]
  RewriteRule ^ - [F,L]
  
# Redirect ONLY /search or /search/ to homepage
RewriteRule ^search/?$ / [R=301,L]

# If request is not a file or directory, send to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

# Force non-www to www (or the other way, depending on what you prefer)
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>
