301 redirect unique url - php

I am looking for away to redirect urls that have a unique job key at the end below are a few examples:
http://domain-name/jf-jobkey&t=zz237933-6561-f56y-8huh-78654& redirects to http://newdomain.com/jobkey=zz237933-6561-f56y-8huh-78654&
http://domain-name/jf-jobkey&t=a5956783-r567-k980-9jko-45678& redirects to http://newdomain.com/jobkey=a5956783-r567-k980-9jko-45678&
The issue is emails have been sent with the old url and don't have a way to see what jobkeys to make an easy 301 redirect.
<?php
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;
}
?>
Here is some code I can catch the url but how could i just pull out the jockey? everything after the =

Related

WordPress Get Permalink Doesn't Get URL 'As Is'

I'm using the function get_permalink() to try and get the Current URL.
I've noticed it doesn't actually get the exact URL as shown in the address bar, for example if it is formatted like:
domain.com?s=one&two&three=0&four=
Is there a function to get the exact current URL?
<?php
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;
}
?>

Get full page URL using php with port number and https

I was looking for the php function that will return the full page url of the page (even rewritten with htaccess).
function returning for example:
https://google.com:8000/yourfolder/yourpage.html
<?php
function fullpageurl() {
$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;
}
?>
Explanation
using $_SERVER["HTTPS"] to check if the SSL is ON or OFF
using $_SERVER["SERVER_PORT"] to check the port number of the website accessed
using $_SERVER["SERVER_NAME"] to get the website host.
using $_SERVER["REQUEST_URI"] to get the current page.

Is the current page the base url in PHP?

I need to see if the current page a user is on is the main page of the website, i.e. there is nothing after the base url.
I'm doing this to exclude some code off the main page.
I asked this question is Javascript, but would like to implement it in PHP
This will probably give you what you are looking for:
$is_home = $_SERVER[ 'REQUEST_URI' ] === '/' ? true : false;
<?php
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;
}
?>
This should give you the url of the current page, when you have this you can check it against the home url.
The following should do the trick:
if (empty($_SERVER['QUERY_STRING'])) {
// no params
}

php get_headers is very slow (takes infinite!) when it requests the URI of current page

Why it takes an infinite amount of time for this ?
function getCurrentPageUrl() {
$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;
}
$headers = get_headers(getCurrentPageUrl());
It's a recursive request. The problem is that you are requesting to load this script and the script which is loading is trying to load it in its self an so on and so on :)

checking user's current page and condition statement

guys im looking for a comprehensive code to check if a visitor is in index.php then showing some lines to him
i mean i want to consider every possibility for this code
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;
}
$curentUrl = curPageURL();
if (preg_match("/index.php/",$curentUrl) || preg_match("/index.html/",$curentUrl)) {
}
but im looking for a more complete code to see if user is in index page of my website
Actually this curPageURL() function has nothing to do here
if ($_SERVER['PHP_SELF'] == "/index.php")
is enough.
But on most PHP sites index.php doesn't mean only index page. but it can be whole site too.
Without complete circumstances this question is too broad to answer.
What about
$_SERVER['SCRIPT_NAME']

Categories