1. Restart the router.
2. Make sure no proxies selected.
Deselect Proxies, if selected.
System Preference > Network > Advanced > Proxies Tab
Unlock the lock if you have to.
Under "Select a protocol…”, uncheck any box if check-marked.
Click "OK” then "Apply”.
https://support.apple.com/guide/safari/if-you-cant-open-a-website-ibrw1071/mac
3. Uninstall any Profile you have not installed knowingly.
Section: Remove a configuration profile from your Mac
Profiles: https://support.apple.com/guide/mac-help/configuration-profiles-standardize-settings-mh35561/m
3. Disable/uninstall any anti-virus software or web monitoring software if installed.
4. If you cannot still connect to internet.
Startup in Safe Mode. https://support.apple.com/lv-lv/HT201262
Login to your account. Launch Safari.
Check for adware.
Run the latest release of Malwarebytes for Mac to remove malware/adware, if installed on your Mac.
For instructions: Install Malwarebytes for Mac v4 Uninstall Malwarebytes for Mac
Click the “Scan Now” button. Once done, quit Malwarebytes for Mac.
Restart the computer and relaunch Safari holding the shift key down.
Scan for Malware again
Click in the menu bar and choose “Restart”