Sami Sami - 1 month ago 5x
Apache Configuration Question

htaccess - Understanding the different between two RewriteCond conditions

I would be so appreciative if somebody would explain the differences between the Condition 1 and Condition 2 for the below htaccess code.

Condition 1

RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

Condition 2

RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]


The thing is for your rules is that you don't need 2 rules to accomplish the same goal. They both redirect to https version of your site, so you can combine the conditions using [OR]

RewriteEngine on
RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^(.*)$$1 [L,R=301]

So that will redirect anything that is not http to https without www (or any other subdomain). And redirect www to non www with https. 2 conditions same rule.