Using .htaccess, I need to change any URL of this kind https://example.com:80/webtrees/anything_else by exactly the same, but with 443 instead of 80

Note that I already have this in my .htaccess (it is there to change from http to https, it should stay there, and I do not understand this syntax): RewriteEngine on RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule (.*) https://example.com/$1 [R=301,L]


  • 1
    Port 443 is used by HTTPS connection – IiroP Jul 21 '17 at 17:26
  • Just stop serving content on port 80. You can't rely on a redirect. Then they either get the redirected page or nothing. – HackSlash Jul 21 '17 at 21:06

This was answered over at Stack Exchange:


I'm going to modify the answer to fit your situation. It says "CONDITION: If not 443 then rewrite to https. This should strip out that port data. Your previous condition was protocol based and not port based.

    # redirect to 443 if current port is not 443 
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://example.com/$1 [R=301,L]

WARNING: I would not rely on these rules if you are trying to force https. I would turn off port 80 altogether. That way if they get around your rules they will see a 404 error.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.