devya Posted October 8, 2019 Share Posted October 8, 2019 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 More sharing options...
Hayri ASLAN Posted October 8, 2019 Share Posted October 8, 2019 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> 4 Link to comment Share on other sites More sharing options...
Ron Posted October 8, 2019 Share Posted October 8, 2019 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 More sharing options...
devya Posted October 9, 2019 Author Share Posted October 9, 2019 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 More sharing options...
devya Posted October 9, 2019 Author Share Posted October 9, 2019 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 More sharing options...
TimKieu Posted June 29, 2022 Share Posted June 29, 2022 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 More sharing options...
rgreat Posted January 31, 2023 Share Posted January 31, 2023 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; 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now