Announcement

Collapse
No announcement yet.

SSL redirect in htaccess

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • SSL redirect in htaccess

    Hi EspoCRM Team,

    We have installed a SSL certificate, updated the siteURL parameter and works perfect with the CRM. However, we haven't been able to redirect http to https.

    We know this can be done from the htaccess file. However, we haven't been able to set it up correctly and would like to avoid having issues with what's already in this file.

    Can you please guide us in the correct code we need to insert/replace in the htaccess file?

    Thanks for your time and help.

  • #2
    hello maybe this : https://www.freecodecamp.org/news/ho...sing-htaccess/

    Comment


    • #3
      Hi item ,

      Thanks for the help. However, we haven't been able to make it work.

      This is our htaccess right now. Our CRM is hosted in a folder (https://mysite/crm/ is an example):

      HTML Code:
      <ifModule mod_headers.c>
        Header always set Access-Control-Allow-Methods "POST, GET, PUT, PATCH, DELETE"
      </ifModule>
      
      DirectoryIndex index.php index.html
      
      <IfModule mod_rewrite.c>
        RewriteEngine On
      
        RewriteCond %{SERVER_PORT} 80
        RewriteCond %{REQUEST_URI} folder
        RewriteRule ^(.*)$ https://mysite/crm/$1 [R,L]
      
        # PROTECTED DIRECTORIES
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^/?(data|api)/ - [F]
      
        RewriteRule ^/?data/config\.php$ - [F]
        RewriteRule ^/?data/logs/ - [F]
        RewriteRule ^/?data/cache/ - [F]
        RewriteRule ^/?data/upload/ - [F]
        RewriteRule ^/?data/\.backup/ - [F]
        RewriteRule ^/?application/ - [F]
        RewriteRule ^/?custom/ - [F]
        RewriteRule ^/?vendor/ - [F]
        #END PROTECTED DIRECTORIES
      
        RewriteRule .* - [E=HTTP_ESPO_CGI_AUTH:%{HTTP:Authorization}]
      
        RewriteRule reset/?$ reset.html [QSA,L]
      </IfModule>
      What is missing?

      Thanks for the help.

      Comment


      • #4
        Hi yuri ,

        Can you please help us with this?

        Thanks for your time.

        Comment


        • #5
          Pablo Not sure how I did mine, I think I just added a HTTPS certificate and it work (it been a couple of months). But here my our htaccess, hope it help.

          Code:
          # BEGIN WordPress
          # The directives (lines) between `BEGIN WordPress` and `END WordPress` are
          # dynamically generated, and should only be modified via WordPress filters.
          # Any changes to the directives between these markers will be overwritten.
          <IfModule mod_rewrite.c>
          RewriteEngine On
          RewriteBase /
          RewriteRule ^index\.php$ - [L]
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule . /index.php [L]
          </IfModule>
          
          # END WordPress
          # DO NOT REMOVE THIS LINE AND THE LINES BELOW SSL_REDIRECT:espocrmwebsitehere.com
          RewriteEngine on
          RewriteCond %{HTTPS} off
          RewriteCond %{HTTP_HOST} (www\.)?espocrmwebsitehere.com
          RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
          # DO NOT REMOVE THIS LINE AND THE LINES ABOVE SSL_REDIRECT:espocrmwebsitehere.com

          Comment


          • #6
            Hey esforim , it WORKED! Thanks a lot.

            For the rest looking for an answer, just add the following to your .htaccess (edit the domain name):

            HTML Code:
            # DO NOT REMOVE THIS LINE AND THE LINES BELOW SSL_REDIRECT
            RewriteEngine on
            RewriteCond %{HTTPS} off
            RewriteCond %{HTTP_HOST} (www\.)?www.mycrm.com
            RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
            # DO NOT REMOVE THIS LINE AND THE LINES ABOVE SSL_REDIRECT
            Last edited by Pablo; 05-15-2020, 07:39 PM.

            Comment


            • esforim
              esforim commented
              Editing a comment
              Ah yes, my top code was for a Wordpress website. The bottom bit is for the purpose of HTTPS redirection.
          Working...
          X