In JavaScript, we can check if the url is different, we have window.location.href
There you go:
var urlAtual = window.location.href;
var urlCadastro = "www.teste.com/cadastro";
if(urlAtual != urlCadastro){
window.location.href = "www.teste.com/login";
}
What have I tried, would it work?
$atacadoLogado = $this->helper('customer')->isLoggedIn();
$urlDoCadastro = "https://www.meusite.com/cadastro";
$pegarDominio = $_SERVER['HTTP_HOST'];
$urlAtualizada = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://" . $pegarDominio . $_SERVER['REQUEST_URI'];
if(!$atacadoLogado && $urlAtualizada != $urlCadastro){
header("Location: https://www.meusite.com/login");
}