Jump to content

Redirect from HTTP to HTTPS [SOLVED]


devya

Recommended Posts

Dear all,

I have success to implement the SSL for our new project UNIGUI.

But i have a problem to redirect to from http to https.

My http apps is like http://erp1.domain.com:8088/     and i want to redirect  to https://erp.newdomain.com:8099/

It's because we already have many customers use it. and now we link to a local bank, and need a secure connection to be done.

I already try to looking our forums for an answer but I don't understand and lose.

can help me to give the clue ?

 

Link to comment
Share on other sites

Hello

ServerModule-> CustomMeta

<script language="JavaScript">
function redirectHttpToHttps()
{
    var loc = window.location.href+'';
    if (loc.indexOf('http://')==0){
      window.location.href = loc.replace('http://','https://');
    }
}
redirectHttpToHttps();
</script>

 

  • Like 4
Link to comment
Share on other sites

On Apache I use the rewrite engine, set up in httpd.conf:

RewriteEngine On
RewriteCond %{THE_REQUEST} !\.php [NC]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L] 

 

Link to comment
Share on other sites

15 hours ago, Ron said:

On Apache I use the rewrite engine, set up in httpd.conf:


RewriteEngine On
RewriteCond %{THE_REQUEST} !\.php [NC]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L] 

 

Hi Ron,

i am not use any web server, i am use Unigui apps. And thank you for your advise.

Link to comment
Share on other sites

15 hours ago, Hayri ASLAN said:

Hello

ServerModule-> CustomMeta


<script language="JavaScript">
function redirectHttpToHttps()
{
    var loc = window.location.href+'';
    if (loc.indexOf('http://')==0){
      window.location.href = loc.replace('http://','https://');
    }
}
redirectHttpToHttps();
</script>

 

Hi Hayri ASLAN,

I am testing you code into my testing server, and it works very well.

I will testing on to my production server and let you know.

Thank you for your code,.

 

It works perfectly, i have been tested on my production server.

Thank you Hayri...

Link to comment
Share on other sites

  • devya changed the title to Redirect from HTTP to HTTPS [SOLVED]
  • 2 years later...

Based on Hayri ASLAN solution by CustomMeta editor, my guy recommend using code for production environment:

//auto HTTP -> HTTPS  on production
      CustomMeta.Append('<script language="JavaScript">' + #13#10 +
      'function redirectHttpToHttps()'                  + #13#10 +
      '{'                                               + #13#10 +
          'var loc = window.location.href+'';'           + #13#10 +
          'if (loc.indexOf(''http://'')==0){  '            + #13#10 +
            'window.location.href = loc.replace(''http://'',''https://'');  '  + #13#10 +
          '}    '                                         + #13#10 +
     ' }       '                                          + #13#10 +
      'redirectHttpToHttps(); '                           + #13#10 +
      '</script> ');

Link to comment
Share on other sites

  • 7 months later...

A bit more universal approach. Still not perfect, though.

if HTTPSRedirect then begin
  var Port1:='';
  var Port2:='';
  if Port<>80 then Port1:=':'+Port.ToString;
  if SSL.SSLPort<>443 then Port2:=':'+SSL.SSLPort.ToString;

  var s:='';
  if (Port1<>'') or (Port2<>'') then begin
    s:='      if (loc.indexOf('''+Port1+'''+''/'')>0){'#13#10+
       '        loc = loc.replace('''+Port1+'''+''/'','''+Port2+'''+''/'');'#13#10+
       '      }'#13#10;
  end;

  s:='<script language="JavaScript">'#13#10+
     'function redirectHttpToHttps()'#13#10+
     '{'#13#10+
     '    var loc = window.location.href+'''';'#13#10+
     '    if (loc.indexOf(''http://'')==0){'#13#10+
     '      loc = loc.replace(''http://'',''https://'');'#13#10+
     s+
     '      window.location.href = loc;'#13#10+
     '    }'#13#10+
     '}'#13#10+
     'redirectHttpToHttps();'#13#10+
     '</script>';

  CustomMeta.Text:=s;
end;

 

  • Like 1
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...