Last active
July 7, 2016 20:00
-
-
Save adrianrodriguez/e6f5ac6452bddb99a2dac39a6c5435ab to your computer and use it in GitHub Desktop.
A problem finally solved. Redirecting non HTTP and non WWW to www and https for MAIN DOMAIN ONLY.
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
# We had a specific need for a client that wanted HTTPS for one domain but not subdomains | |
# that also ran a lot of sites locally. So we ran into an issue after launching without the www prefix. | |
# For days I looked for a solution and tried to get things working, with hours spent attempting many different ones. | |
# After so long and taking some time to work on another project I stumbled upon this article: https://www.siteground.com/kb/how_to_redirect_nonwww_urls_to_www/ | |
# After sifting through the comments I found the first chunk of code below that did everything for the main domain, while keeping what I had below for the subdomains to redirect from HTTPS | |
# Also be sure the main blog is updated to http://www.domain.com in the wp_options table wherever applicable. | |
# for main domain | |
RewriteCond %{HTTPS} off | |
RewriteCond %{HTTP_HOST} ^domain.com [NC,OR] | |
RewriteCond %{HTTP_HOST} ^www.domain.com [NC] | |
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301] | |
# for sub domain | |
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com [NC] | |
RewriteCond %{HTTPS} on | |
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment