Does this htaccess do anything?

I have this bit of code in my root .htaccess that’s been there forever. Looking at it now I don’t think it’s doing anything. I haven’t removed it because I’m just not sure!

RewriteCond %{SERVER_PORT}s ^(80s|443(s))$ 
RewriteCond %2-%{HTTP_HOST} ^(s?)-(mysite\\.com)$ [NC] 
RewriteRule ^(.*)$ http%1://www.%2/$1 [R=301,L]

It looks to me like the conditions will ALWAYS match, regardless of whether the request uses https or not. Though if it did, that would mean a redirect loop.

I don’t think it’s right, but does it look like it’ll do anything?

There’s a slightly different version in one of the subdirectories:

RewriteCond %{SERVER_PORT}s ^(80s|443(s))$ 
RewriteCond %2-%{HTTP_HOST} ^(s?)-(mysite\\.com)$ [NC] 
RewriteRule .* http%1://www.%2%{REQUEST_URI} [R=301,L]

Ah of course. Thank you. I missed that.

from the looks of it I’d say it redirects


Those two blocks go to a lot of effort to determine the {HTTPS} value without addressing it directly only to redirect to the www’d version of the domain.

FWIW, I like the second version more because of the use of the {REQUEST_URI} variable in the redirection despite prefering .? to .* in the regex.

Thanks, Rémon. Spot-on answer!