Client asked me to automatically redirect any urls with a pound sign in them to a version without a pound sign, but I don’t think I am detecting a # in any of my urls with this formula. I emailed myself a sample URL using the curPageURL() formula and it didn’t contain the trailing # sign in the url I was testing.
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
if(stripos($currenturl,'#'))
{
Header( "HTTP/1.1 301 Moved Permanently" );
$location = 'Location: ' . str_replace('#','',$currenturl) . '/';
Header($location);
}
*Correction – I said at the end in the Title, and I mean the end, my code here apparantly detects for the pound sign anywhere in the url. *
The part after the
#is a “hash” or “fragment”. It is entirely client-side – it is never sent to the server (and if it is, it results in an error). As such, your PHP script will never see it, and can’t therefore fix it. This is correct behavior, and by design.That said, you could check for the #fragment using a client-side solution (e.g. in JS with
document.location.hash) and redirect from there.