cancel
Showing results for 
Search instead for 
Did you mean: 

Magento is not redircting from http to https

Magento is not redircting from http to https

I have installed ssl and also change base url(secure and unsecure).

Its start working but after some time its redirect back on http and after that its showing blank page.

Merging of css and js stop working.

After clearing cache from server then its start working again.

I also tried this code in index.php

 

 if( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) ) {
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}

But no luck. I am using nginx and magento 1.9.0.1.

 

5 REPLIES 5

Re: Magento is not redircting from http to https

I used something like this in .htaccess file (provided that you use Apache):

RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,QSA,NC,L]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

You can stick those lines right after RewriteEngine on if your don't know where to put them. 

Tanel Raja

Re: Magento is not redircting from http to https

I had already tried it but its not working. Is there any file required to update?

Re: Magento is not redircting from http to https

It might be because your web server doesn't allow .htaccess overrides. In such case, it's hosting problem and there's very little I can do.

Tanel Raja

Re: Magento is not redircting from http to https

I am using AWS server with nginx. and using this code

map $http_user_agent $bad_bot {
  default 0;
   ~(?i)(Ahrefsbot|Baiduspider|YandexBot|Abonti|ShopWiki|FatBot|UnisterBot|Baidu|BLEXBot|Twengabot|httrack|WinHTTrack|htmlparser|urllib|Zeus|scan|email|PyQ|WebCollector|WebCopier|WebCopy|webcraw|LWP::simple|Havij) 1;
}

{{301_redirect}}

server {
    listen 80;
    {{ssl_listener}};
    {{server_name}};
    {{ssl_certificate}};
    {{ssl_certificate_key}};
    ssl_session_cache  builtin:1000  shared:SSL:10m;
    ssl_session_timeout  10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128:AES256:AES:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK';
    ssl_prefer_server_ciphers on;
    ssl_stapling on;
    ssl_stapling_verify on;
    client_max_body_size 50m;
    {{root}};

    {{nginx_access_log}};
    {{nginx_error_log}};

    if ($bad_bot = 1) {
      return 403;
    }

    rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
    rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;

    location /lib/minify/ {
     allow all;
    }

    location ~ (/(app/|includes/|pkginfo/|var/|report/config.xml)|/\.+) {
      deny all;
    }

    #rewrite ^/blog$ /blog/$1 permanent;
    
    #location /blog/ {
    #  try_files $uri $uri/ /blog/index.php?$args;
    #}

    try_files $uri $uri/ /index.php?$args;
    index index.php index.html index.htm;

    location ~ \.php$ {
       include /etc/nginx/naxsi.rules;
       BasicRule wl:0 mz:BODY;
       include fastcgi_params;
       fastcgi_intercept_errors on;
       fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       try_files $uri =404;
       fastcgi_pass 127.0.0.1:{{php_fastcgi_port}};
       fastcgi_read_timeout 3600;
       fastcgi_send_timeout 3600;
       fastcgi_param HTTPS $fastcgi_https;
       fastcgi_param SERVER_PORT 80;
       fastcgi_param PHP_VALUE "
         error_log={{php_error_log}};
         memory_limit=512M;
         max_execution_time=90;";
       #fastcgi_param MAGE_RUN_CODE "store_code";
       #fastcgi_param MAGE_RUN_TYPE "website";
    }

    gzip                on;
    gzip_disable        "msie6";
    gzip_vary           on;
    gzip_proxied        any;
    gzip_comp_level     8;
    gzip_buffers        16 8k;
    gzip_http_version   1.1;
    gzip_types          text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/png image/gif image/jpeg;

    location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|eot|mp4|ogg|ogv|webm|zip|swf)$ {
      add_header Access-Control-Allow-Origin "*";
      expires max;
      access_log off;
    }

    if (-f $request_filename) {
      break;
    }
}

Re: Magento is not redircting from http to https

I am using AWS server with nginx. and using this code