Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.