Rewriting HTTP url to HTTPS using regular expression and javascript

后端 未结 3 838
生来不讨喜
生来不讨喜 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:41

    Cannot it be done by simply replacing the http string?

    if(url.match('^http://')){
         url = url.replace("http://","https://")
    }
    

提交回复
热议问题