Simple Method to Get the Current Page URL in PHP


Simple Method to Get the Current Page URL in PHP

Current Page URL in PHP

This tutorial we are going to see How to Get the Current Page URL in PHP.This method Help’s to get the Proper Canonicalization URL for the current page.Proper Canonicalization is good for SEO.

 

 

Let’s come to our tutorial part.this tutorial we are going to see about.Get the Current Page URL in PHP and SEO URL canonicalization.

Steps to Get the Current Page URL in PHP

Use the below PHP Code to find the Current Page URL in PHP we use $_SERVER to get the current page URL

<?php $CurrenURL = $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; echo $CurrenURL; ?>

SEO URL canonicalization Method

SEO URL canonicalization in Custom Designed PHP website’s

<?php $current_page = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; echo '<link rel="canonical" href="'.$current_page.'"/>'; ?>

For HTML website’s

<link rel="canonical" href="http://www.website.com" />

Note – Every time you need add the about canonical meta tag on every new HTML page with proper URL

PHP Get a Current Page URL For Share Buttons (For Custom Design PHP websites)

Facebook

href="http://facebook.com/sharer.php?u=<?php echo $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; ?>"

Google+

href="https://plus.google.com/share?url=<?php echo $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; ?>"

Whatsapp

href="whatsapp://send?text=<?php echo $_GET["name"]; ?> YOUR CUSTOM TEXT- <?php echo $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; ?>"

Twitter

href="https://twitter.com/intent/tweet?text=YOUR CUSTOM TEXT <?php echo $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; ?>"

Facebook Og URL Graph (PHP websites)

<meta property="og:url" content="<?= "http://www.website.com".$_SERVER['REQUEST_URI']; ?>" />

Facebook Og URL graph for HTML website’s

<link rel="canonical" href="http://www.websitecom/" itemprop="url">

Blogger URL canonicalization

<link rel='canonical' expr:href='data:blog.url'/>

Get the Current page URL in WordPress site

global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );

From the Pro’s

Proper URL canonicalization helps to the Avoid Duplicate Content Problems.

Check My SEO pack for Custom Designed Website’s

If you have Any Doubts please Feel free to Comment here I will Help you

Read – htaccess Redirect Method non-www to www and HTTP to HTTPS



Was this article helpful?
Thanks!

Your feedback helps us improve Allwebtuts.com