Skip to content

Instantly share code, notes, and snippets.

@AndrewChamp
Last active February 13, 2024 20:37
Show Gist options
  • Save AndrewChamp/3e4035341c2a3e8b8e1c75d7420fc0c3 to your computer and use it in GitHub Desktop.
Save AndrewChamp/3e4035341c2a3e8b8e1c75d7420fc0c3 to your computer and use it in GitHub Desktop.
Force Port 80 or Port 443 via .htaccess. This will also remove www. from the url.
# FORCE PORT 80 (insecure / regular traffic)
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
###########################################################
#FORCE PORT 443 && REMOVE WWW. (secure / SSL)
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment