Lambneck Posted August 23, 2011 Share Posted August 23, 2011 Is there a way to dynamically print the url of a web page once it loads? If so, how? This is for metadata purposes. Thanks! Link to comment https://forums.phpfreaks.com/topic/245530-dynamically-print-url/ Share on other sites More sharing options...
requinix Posted August 23, 2011 Share Posted August 23, 2011 Besides with $_SERVER["REQUEST_URI"]? Link to comment https://forums.phpfreaks.com/topic/245530-dynamically-print-url/#findComment-1261091 Share on other sites More sharing options...
Lambneck Posted August 23, 2011 Author Share Posted August 23, 2011 So this will do it? <?php print $_SERVER["REQUEST_URI"]; ?> Great thanks! That's all i needed to know. Link to comment https://forums.phpfreaks.com/topic/245530-dynamically-print-url/#findComment-1261104 Share on other sites More sharing options...
codefossa Posted August 23, 2011 Share Posted August 23, 2011 $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; Link to comment https://forums.phpfreaks.com/topic/245530-dynamically-print-url/#findComment-1261110 Share on other sites More sharing options...
Lambneck Posted August 23, 2011 Author Share Posted August 23, 2011 So would something like the following work? <link rel="canonical" href="<?php $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; print $url; ?>" > Link to comment https://forums.phpfreaks.com/topic/245530-dynamically-print-url/#findComment-1261125 Share on other sites More sharing options...
requinix Posted August 24, 2011 Share Posted August 24, 2011 Yes, but either (a) you aren't using rel=canonical correctly or (b) you don't need to specify it because the canonical URL will always be the page's URL - you aren't adding any useful information and are implying things that might not be true. The idea is that there could be multiple URLs to access a certain page (notably: URLs with varying query string parameters), so you specify a canonical URL to provide a "primary" location of the page. Google's Webmaster Tools has a page on the subject. Link to comment https://forums.phpfreaks.com/topic/245530-dynamically-print-url/#findComment-1261446 Share on other sites More sharing options...
Lambneck Posted August 27, 2011 Author Share Posted August 27, 2011 Thanks requinix. I see that's a problem. So how then can i dynamically generate the canonical url to match the pages content? Link to comment https://forums.phpfreaks.com/topic/245530-dynamically-print-url/#findComment-1262691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.