Howto change the port in an URL using .htaccess
This was answered over at Stack Overflow:
https://stackoverflow.com/questions/23027847/htaccess-specific-url-to-different-port
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.
Related videos on Youtube
![Admin](/assets/logo_square_200-5d0d61d6853298bd2a4fe063103715b4daf2819fc21225efa21dfb93e61952ea.png)
Admin
Updated on September 18, 2022Comments
-
Admin almost 2 years
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 80Note 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]
Thanks!
-
Admin almost 7 yearsPort 443 is used by HTTPS connection
-
Admin almost 7 yearsJust stop serving content on port 80. You can't rely on a redirect. Then they either get the redirected page or nothing.
-