Rewriting HTTP url to HTTPS using regular expression and javascript

后端 未结 3 839
生来不讨喜
生来不讨喜 2021-02-04 00:30

I\'m in a situation where I need to rewrite an url in javascript and switch it from http protocol to https.

I can match https urls with:

if(url.match(\'         


        
3条回答
  •  你的背包
    2021-02-04 00:58

    Replace directly with a regex :

    url = url.replace(/^http:\/\//i, 'https://');
    

提交回复
热议问题