This is the best solution. The back() and forward() methods aren't guaranteed to work.
driver.execute_script("window.history.go(-1)")
The JavaScript passed here gives access to the pages’ Dom to navigate to the previous URL. I hope this resolves the issue.
If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training!