We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32025
    • 305 Posts
    I am trying to force URL's to use HTTPS. I know I can do it via .htaccess and found several posts with .htaccess coding but it did not work in my case, I assume since I already have some defintions.

    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.

    This question has been answered by BobRay. See the first response.

      Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
    • discuss.answer
      • 3749
      • 24,544 Posts
      I added this at the end of the section that rewrites www.domain.com to domain.com:

      RewriteRule (.*) https://yourdomain.com/$1 [R=301,L]

        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 32025
        • 305 Posts
        Thank you Bobray, your solution worked!

        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.

          Making the web a better place on site at a time! Dayton Web Design: http://www.dayton-web-design.com/
          • 3749
          • 24,544 Posts
          Glad I could help. smiley
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 36686
            • 165 Posts
            Hi @daytonwebdesign or @bobray,

            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!
              • 36686
              • 165 Posts
              I think I actually found a working solution in the end:

              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.
                • 44212
                • 1 Posts
                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!