Skip to content

Instantly share code, notes, and snippets.

@christoferw
Created September 3, 2018 13:13
Show Gist options
  • Save christoferw/50fad6a6bd763258883837355f376be2 to your computer and use it in GitHub Desktop.
Save christoferw/50fad6a6bd763258883837355f376be2 to your computer and use it in GitHub Desktop.
htaccess Wordpress: Force SSL and WWW or NON-WWW
RewriteEngine on
# Force www:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Alternativ: Force NON-WWW
#RewriteBase /
#RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
#RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
# Force SSL: From http://stackoverflow.com/q/24322035/
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment