Let's say this is in a file called index.php
at http://mysite.com/
:
if ( !logged_in() ) {
header("Location: http://www.mysite.com/login/");
}
If someone enters the url http://mysite.com/#profile/edit/
, PHP copies the "#profile/edit/" over to the redirected address. Accordingly, the user is sent to: mysite.com/login/#profile/edit/
. This is not the behaviour that I want. I simply want it to redirect to mysite.com/login/
.
Does anyone know how to tell PHP to only use the location that I give it, and ignore any other information that it thinks it's supposed to use?
EDIT: The reason this comes up as an issue for me is that I'm using the routing system of Backbone
(which relies on "#parms" for navigation).
EDIT2: Looks like PHP redirection just isn't safe when working with hashes, as the behaviour is not consistent across browsers. An alternative, of course, is to use a javascript-based solution instead:
function redirect(href) {
// window.location.hash = ""; (not necessary)
window.location = href;
}
However, this is a serious pain in the ass, as I now need PHP to tell javascript to do the redirection later on in the page. But, if I don't, when a user clicks on a bookmark (made when they were logged in) of mysite.com/#profile/
it redirects them to mysite.com/login/#profile/
, at which point they are told they've reached an invalid URL.
Ugh.