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('^http://')){
but how do I form the https url using regular expressions and javascript?
url = "https://" + ?;
Replace directly with a regex :
url = url.replace(/^http:\/\//i, 'https://');
Cannot it be done by simply replacing the http string?
if(url.match('^http://')){
url = url.replace("http://","https://")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With