Skip to content

Instantly share code, notes, and snippets.

@schlessera
Created May 8, 2015 19:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save schlessera/8d5091c021fb2495b1f6 to your computer and use it in GitHub Desktop.
Save schlessera/8d5091c021fb2495b1f6 to your computer and use it in GitHub Desktop.
Redirect HTTP to HTTPS, for the main domain as well as all subdomains.
# Redirect HTTP to HTTPS, for the main domain as well as all subdomains.
#
# Example:
# http://domain.com/ => https://domain.com/
# http://subdomain.domain.com/ => https://subdomain.domain.com/
#
# Make sure you replace "replacewithyourdomain" with your actual root domain!
#
# @author: Alain Schlesser <alain.schlesser@gmail.com>
# The HTTP to HTTPS redirection code needs to go in front of the WordPress code.
# Make sure RewriteEngine is on
RewriteEngine On
# First, redirect HTTP subdomains to HTTPS subdomains
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^(.*)\.replacewithyourdomain\.com$
RewriteRule ^(.*)$ https://%1.replacewithyourdomain.com/$1 [R=301,L]
# Now, redirect HTTP main domain to HTTPS main domain
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} ^replacewithyourdomain\.com$
RewriteRule ^(.*)$ https://replacewithyourdomain.com/$1 [R=301,L]
# BEGIN WordPress
# [Here is your standard WordPress code, you should not modify this.]
# END WordPress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment