HTTPS redirect not working on one TLD

Nextcloud version 11.0
Operating system and version 16.0 server
PHP version 7
Is this the first time you’ve seen this error and can you replicate it?:
yes and yes

The issue you are facing:

I am all of the sudden having issues with HTTPS redirecting on one of my sites TLD. The .com will redirect to https fine… however the .net will not redirect to HTTPS.

I know I had this working … I hadnt tried the .net for awhile. The only thing I can think of is the nextcloud upgrade that I did that could have caused it.

I usually have everything I did to get something to work jotted down but this one I cannot find.

I do believe it was something in my etc/apache2/sites-available/000-default.conf which is my virtualhost 80

the thing that i have in there now is

RewriteEngine on RewriteCond %{SERVER_NAME} RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

This I think was different to cover all the domains but Im not real sure how it used to be set up…

I did try to use the letsencrypt again and nothing changed when selecting redirect all traffic over https, I thought that worked the first time I set it up.

any help would be great thanks!

ok so after me constantly trying things I got lucky and got something that works. No idea if its the right way or the best way though.

So what I ended up with was this

RewriteEngine on
RewriteCond %{SERVER_NAME} ^ [OR]
RewriteCond %{SERVER_NAME} ^
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

I had to remove the = and add the ^ This makes it work with the www as well. Then added the [OR] before the new entry for the second TLD (.net) RewriteCond %{SERVER_NAME} ^

and just in case someone is reading this and is not sure. You to have to change the to your website domain name.

so IF anyone sees this and sees that this isnt the right way or the best way … please let me know.


If you want to use it with and without www but not with other subdomains, you can try this:

RewriteCond %{SERVER_NAME} ^(www.)?

and to get it with .com and .net

RewriteCond %{SERVER_NAME} ^(www.)?site.(net|com)

oh cool. Ya that works too.

Ill use the one you suggested. Im not sure if there is a performance difference from on or to the other but yours does have it all in one line, so Ill stick with that one… Thanks

If you are concerned about performance, you should rather use Redirect:

and use mod_rewrite only if you need a more complex rewriting scheme.