Created
May 8, 2015 19:12
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 <[email protected]> | |
# 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