I have following piece of code in my ngOnInit event.
ngOnInit()
{
let Url = window.location.href.trim().toLocaleLowerCase();
if (Url.startsWith("https://"))
{
console.log('HTTPS');
let NewUrl = Url.replace("https://", "http://");
this.document.location.href = NewUrl;
}
}
My aim is that if Url is having HTTPS then I need to redirect to same Url but with HTTP. But this piece of code is not working even though code comes to the HTTPS block. No error or warning is shown either. I already have tried using
I am using
How to achieve my purpose?
Thanks in advance,
I had to do this in IIS. No solution worked n JavaScript.
you should consider a bit cleaner if condition -
if (window.location.protocol === 'https:') {
const correctProtocolUrl = window.location.href.trim().toLocaleLowerCase().replace('https://', 'http://');
window.location.href = correctProtocolUrl;
}
I've tested this in angular 13, but expecting similar behaviour since angular should not do anything with window.
But if you have backend solution I think that is the best way this can be done.