Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.9k views
in Technique[技术] by (71.8m points)

javascript - URL Redirect for Auth

My login page goes to mywebsite.com/dashboard.html?fromauth but if it does it without the ?fromauth I want to redirect them to the login page. The challenge is I cannot have a .htaccess due to provider restrictions

question from:https://stackoverflow.com/questions/65907526/url-redirect-for-auth

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Change the URL to ?fromauth=1, and then you can use JavaScript to read the page URL:

var URLString = window.location.href;
var URL = new URL(URLString);
var fromauth = URL.searchParams.get("fromauth");
if (fromauth != 1){
    window.location.replace("http://www.mywebsite.com/login");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...