<![CDATA[ Forcing HTTPS and using friendly URLs. - My Forums]]> https://forums.modx.com/thread/?thread=102335 <![CDATA[Forcing HTTPS and using friendly URLs.]]> https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-551462
My templates, chuncks and pages are all generic settings. There is no http: so the site should convet to https: fairly easily I would assume.

First I found that I was supposed to change this setting from http to https:

System Settings: server_protocol
Value: https

I believe my .htaccess file is the problem. This is what I have:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

RewriteCond %{HTTP_HOST} ^MyWebsite\.biz$ [OR]
RewriteCond %{HTTP_HOST} ^www\.MyWebsite\.biz$
RewriteRule ^/?$ "https\:\/\/www\.My\-Website\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^MyWebsite\.co$ [OR]
RewriteCond %{HTTP_HOST} ^www\.MyWebsite\.co$
RewriteRule ^/?$ "https\:\/\/www\.My\-Website\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^MyWebsite\.net$ [OR]
RewriteCond %{HTTP_HOST} ^www\.MyWebsite\.net$
RewriteRule ^/?$ "https\:\/\/www\.My\-Website\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^MyWebsite\.us$ [OR]
RewriteCond %{HTTP_HOST} ^www\.MyWebsite\.us$
RewriteRule ^/?$ "https\:\/\/www\.My\-Website\.com" [R=301,L]

RewriteCond %{HTTP_HOST} ^MyWebsite\.info$ [OR]
RewriteCond %{HTTP_HOST} ^www\.MyWebsite\.info$
RewriteRule ^/?$ "https\:\/\/www\.My\-Website\.com" [R=301,L]


I have found this code posted in the forums:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.your_domain.com$
RewriteRule ^(.*)$ http://www.your_domain.com/$1 [R=301]


but it doesn't work when pasted in my .htaccess. I assume due to these existing lines. I don't know how to merge this. Can anyone help me out here. Really need my site to automatically direct to HTTPS:// when non-secure is clicked.
]]>
wbbuilder Jun 03, 2017, 01:17 AM https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-551462
<![CDATA[Re: Forcing HTTPS and using friendly URLs.]]> https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-564229 Quote from: sketchi at Jan 15, 2019, 03:39 PM
I think I actually found a working solution in the end:

# Redirect to HTTPS without www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]


Putting the last 5 lines of code *after* the friendly URLs part was the key I think.

Saved the day! Thank you so much!]]>
forkworks Feb 25, 2019, 01:30 PM https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-564229
<![CDATA[Re: Forcing HTTPS and using friendly URLs.]]> https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-563584
RewriteEngine On
RewriteBase /

# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

# Redirect to HTTPS without www
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]


Putting the last 5 lines of code *after* the friendly URLs part was the key I think.]]>
sketchi Jan 15, 2019, 03:39 PM https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-563584
<![CDATA[Re: Forcing HTTPS and using friendly URLs.]]> https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-563577
I'm having a similar problem with a site where I have three different contexts with individual domain names. I've installed SSL certificates for all domains but can't figure out how to set up the .htaccess file to make all the domains go to https and non-www.

Would you mind posting the full .htaccess that worked for you? I'm aware this is an old thread but hoping you might still be able to help since I've been trying all sorts of things and nothing seems to work.

Basically this is what I'm after:

- Three different domains that go to different contexts (this is set up in MODX and index.php and working fine)
- Route www to non-www for all tree domains
- Route http to https for all three domains
- Route both the root and subfolders such as the manager

Many thanks!]]>
sketchi Jan 15, 2019, 02:04 PM https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-563577
<![CDATA[Re: Forcing HTTPS and using friendly URLs.]]> https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-551468 ]]> BobRay Jun 03, 2017, 05:20 PM https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-551468 <![CDATA[Re: Forcing HTTPS and using friendly URLs.]]> https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-551467
Right after RewriteBase / I added these 2 lines of code (since I already had rewrite base on line added as well):

RewriteCond %{HTTP_HOST} !^www.yourdomain.com$
RewriteRule (.*) https://www.yourdomain.com/$1 [R=301,L]

And since I want all my URL's to add the www. I added that to your line as well. For those with the same issue don't forget to go to : System Settings> Server type, key = server_protocol and change: http to https or you might have half in half out and a jumbled mess.

]]>
wbbuilder Jun 03, 2017, 12:54 PM https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-551467
<![CDATA[Re: Forcing HTTPS and using friendly URLs. (Best Answer)]]> https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-551464
RewriteRule (.*) https://yourdomain.com/$1 [R=301,L]

]]>
BobRay Jun 03, 2017, 03:44 AM https://forums.modx.com/thread/102335/forcing-https-and-using-friendly-urls#dis-post-551464