Thanks, I changed it the $NewPages, but it didn’t work.
The error message says:
Strict Standards: main() [function.main]: It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Europe/London’ for ‘BST/1.0/DST’ instead in /home/site/public_html/redirect/hash-redirect.php on line 14
Notice: Undefined variable: MaxPages in /home/site/public_html/redirect/hash-redirect.php on line 14
I got the code from here, soI’m not sure what the $MaxPages should be defined as:
You can fix the strict standards error by invoking the date_default_timezone_set() function at the top of your script (with your timezone passed as an argument - see the PHP.net manual for the supported timezones).
The $MaxPages variable looks like it should be the count of one of the URI arrays (it doesn’t matter which one, since they both should contain the same amount of elements):
It has just occurred to me that the value of $_SERVER[‘REQUEST_URI’] will contain a preceding forward slash. You will therefore want to use substr() (or trim(), whichever takes your fancy) against that value to remove the preceding forward slash. There’s also a more optimal way of checking the validity of the URI for your scenario - by using the in_array() function. Here’s how I’d rewrite your script:
date_default_timezone_set("UTC");
// redirects
$redirect = array(
'page1.shtml' => 'newpage1.shtml',
'page2.shtml' => 'newpage2.shtml'
);
$oldPage = substr($_SERVER['REQUEST_URI'], 1);
if(in_array($oldPage, array_keys($redirects), true)) {
header('HTTP/1.1 301 Moved Permanently');
header("Location: {$redirects[$oldPage]}");
die;
}
// no page found, so send out a 404 status code
I am glad it worked, so much easier than posting messages backwards and forwards.
If it is not working on your site, activate the DEBUG comments (change the 0 to 1) to display the variables. You should be able to find why the validation is not calling header(‘Location: …’);
>>> Can I use absolute URLs?
Also remove the remarks on the following and select a more suitable $_SERVER parameter: