Use https

How do I redirect elgg to use https not http? When someone goes to http I would like to redirect to https instead.

  • In your .htaccess you need to add

    RewriteEngine On
    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$$1 [R,L]

    You can find more resources and good reading stuffs at

    I myself am struggling a bit with this because how the users type in your domain name  and how the browser behaves varies a lot,  for example: just "mydomain dot com" typed in Firefox automatically takes to the https site ( I have done a https install of Elgg 3x by web installer) BUT Chrome in mobile does not do this, it shows http www instead, and labels as insecure site ( default behavior, I have not done htaccess changes here)

    Thus users can type in

    mydomain com
    www mydomain com
    http mydomain com
    http www mydomain com
    https mydomain com
    https www mydomain com

    So we need to decide which is the thing that it will redirect to whatever may the user type.
    If you find any useful tips please share.



  • If you are using nginx as a webserver you can use this server block. Just replace with your own ip and yourdomain with whatever your domain name is. If you don't have m or www just leave them out. you can try with just server_name _; as second line if you wish as that should work as well:

    server {
        listen      172..0.0.1:80 default server;
        return 301 https://$host$request_uri;


  • You can add the following to your htaccess file right after the line "# If you must add RewriteRules to change hostname, add them directly below (above all the others)"

    #Http to https
    #Exclude subdomains
    RewriteCond %{HTTP_HOST} ^(www\.)?$ [NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^{REQUEST_URI} [NC,L,R]
    #add www on ssl
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]

    what does the below piece of code do?

    This is a tested code and I am using the same code in my server. You can also test it if you want at

  • Thats great help. Many thanks @Rohit Gupta

  • on your server with cpanel just do a redirection from http: // mysite to https: // mysite
  • @adrew22a.. Just for the headsup.. we live in an era where we have something called as "Google" where you can almost find everything.. 

    Just wanted to make sure the you knew about google before telling you the solution.

    #Http to https
    #Exclude subdomains
    RewriteCond %{HTTP_HOST} ^(www\.)?$ [NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^{REQUEST_URI} [NC,L,R]
    #add www on ssl
    RewriteCond %{HTTPS} on
    RewriteCond %{HTTP_HOST} ^www\.
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]

    I hope this helps.. I only changed 3 things..
    1st: Line 5 - I removed www
    2nd: Line 8: I removed ! sign
    3rd: Line 9: I removed www

    I have not tested the code but i think this might work. And remember to use google.

  • And that kind of attitude is why open source projects die.  People get afraid to ask questions or suggest input.  Thanks for your help though.

  • And that kind of attitude is why open source projects die.

    All I am saying is that people like free buffet. All the solution just served to them on plates. A little curiosity is good. It help you learn new things (and sometimes also contribute to the open source projects, which will definitely keep the project alive). If you would have tried to understand what the piece of code does you could have easily found the solution on your own.

    Anyways, It was not to offend you. I am sorry if it was in-appropriate in any way. 

  • Imho Rohit Gupta has provided actual help with actual code. This is what helps a forum as well as open source run. While this will be out of topic : open source projects' deaths have got nothing to do ( or more or less nothing to do) with "attitudes" in general. During the past 10 years or so there has been no significant new open source project in php. No new open source web scripting language as successful as php too. Just think projects like Elgg, Wordpress, Drupal will never happen again. The world is now sheepishly slave to the trio Google-Apple-Facebook. Many entities now have only fb/ address in billboards and elsewhere and not www address. Apps are killing the open and interconnected net, and for Apps you have to be "slave" to Google or Apple ( and MS). Why Apps are something not like http html php websites - where you host your own either on free or paid servers or even your own server ?? No one complains, no lawsuits !!

    Opensource generation is a dying generation thus. Despite several ongoing projects, its not that the flourishing majority when Tim Lee "invented" www and Rasmus Lerdorf "created" Php. Its sad. Many "opensource" projects got sold to biggies. And many opensource projects made their own commercial firms like Wordpress and Drupal. Opensource and money earning has no conflict with each other as such ( without money you cannot survive) but the spirit ... I dont know. There will be no more "whiz kids" like Matt (Wordpress), Dries (Drupal) or for that matter Ben Werdmuller who started Elgg but has shifted to other priorities now ( I think so). Many opensource projects actually died as the young ones who started these needed money for survival ( or needed to be "more rich") and commercialization of open source was not that much success for most of them. So they had to devote more and more time to jobs ( or in some cases their own companies or in the companies which "purchased" them). Elgg 2x has many and many more plugins( and thus more adoption)  than Elgg 3x will ever have because of the same reason. The number of interested and talented youth who could have contributed are now in look out for actual jobs and money or are absorbed passively in the Apps world or rather than trying out php are chatting on Fb. The existing opensource projects do have some flaws which do not let them flourish, that is another issue.