Reputation: 527
I use PHP to echo the current URL in <link rel="canonical" href="URL" />
on my static website, but unfortunately it also echoes query strings along with it.
http://www.example.com?querystring
gets echoed in canonical, and I'm trying to find a away to echo URLs ignoring query strings and whatever follows it.
I am currently using .
Is there a way I can declare all the necessary code for this once in a global template, and simply echo $url
wherever I require the URL without query strings?
Upvotes: 0
Views: 1979
Reputation: 1
use request.forwardURI to set canonical uri, it removes the query string paramaters
Upvotes: 0
Reputation: 1308
for example you can use parse_url and re-build your query
$url = "http://www.example.com?querystring";
$newUrl = parse_url($url);
echo "http://".$newUrl['host'].$newUrl['path'];
etc
Upvotes: 1
Reputation: 664
Let's say you ahve your URL in variable. Then we will explode the url with delimiter "?" and then echo only the first index of returned array:
$url = http://www.example.com?querystring;
$array = explode("?", $url);
$yourUrl = $array[0];
There you go
Upvotes: 2