An .htaccess file lets you configure Apache per directory without touching the server config, which is why shared hosts rely on it. The same flexibility makes it easy to write a rule that silently does nothing or, worse, loops forever.
The usual test, RewriteCond %{HTTPS} off, is always true when a CDN or load balancer terminates TLS and forwards plain HTTP, so every request redirects to HTTPS again and the browser gives up. Also check the X-Forwarded-Proto header the proxy sets, and redirect only when it is not https.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]A block inside IfModule mod_rewrite.c is skipped without any message when that module is not loaded. That keeps the site up, but it also means a redirect or compression rule can be missing without an error. After deploying, request the plain-HTTP URL and a page with Accept-Encoding: gzip and confirm both behave.
Unlike Nginx, which always compresses HTML once gzip is on, Apache's AddOutputFilterByType compresses exactly the MIME types listed. Leave out text/html and your pages go out uncompressed while your CSS and JavaScript are compressed.
AddOutputFilterByType DEFLATE text/html text/plain text/css application/javascript application/json image/svg+xmlA directive in .htaccess works only if the server's AllowOverride setting permits its group: FileInfo for rewrites, Options for Options -Indexes, AuthConfig for Require. A directive that is not permitted returns a 500 error, and the real reason is in the Apache error log.
Open the Apache .htaccess generator
Slightly. Apache checks for an .htaccess file in every directory on the path to each request. If you control the server, put the same directives in the virtual host and set AllowOverride None.
A 404 does not confirm the file exists. The rule leaves /.well-known reachable, which certificate validation and security.txt need.
No. Nginx ignores .htaccess files. Use the Nginx generators for the same protections.