Reputation: 7327
This is a simplified PHP version of my question:
I want to load http://localhost/test2.php in browser, and if it's missing #test_test, reload immediately with it http://localhost/test2.php#test_test .
<?php
// causes ERR_TOO_MANY_REDIRECTS
if (strpos(strtolower($_SERVER['REQUEST_URI']), 'test_test') === false) {
header("Location: /test2.php#test_test");
}
?>
In short, I want to check for an anchor in an URI, if it's missing, reload the page with it. I am getting ERR_TOO_MANY_REDIRECTS. Any suggestions on how to tackle this?
Upvotes: 0
Views: 74
Reputation: 1037
You can do it using js this way:
let currentUrl = window.location.href;
if (currentUrl.indexOf('#test_test') === -1) {
window.location.href = currentUrl.replace(/(#.+)/gi, '#_test_test');
}
Upvotes: 1