What are the potential pitfalls of using .htaccess to force HTTPS and how can they be avoided?

Potential pitfalls of using .htaccess to force HTTPS include causing infinite redirect loops, breaking certain website functionalities or plugins that rely on HTTP, and inadvertently blocking access to the website. To avoid these issues, ensure that the .htaccess rules are correctly configured to only redirect non-HTTPS traffic to HTTPS and test the website thoroughly after implementing the changes.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]