Jump to content

Redirect


Manny

Recommended Posts

I posted in the server section about some mod_rewrite's I was doing using the .htaccess file. I've set the rewrites up, but having an issue with my PHP redirects.I've included part of my code below. The first four work fine, but I don't understand why the last two aren't even attempting to redirect.

// Server Redirectsif(in_array($_SERVER['REQUEST_URI'],array("/games/predictionleague/","/games/predictionleague/index.php"))) {	header("HTTP/1.1 301 Moved Permanently");	header("Location: " . $siteURL . "/predictionleague");	}	if(in_array($_SERVER['REQUEST_URI'],array("/games/predictionleague/?action=standings","/games/predictionleague/index.php?action=standings"))) {	header("HTTP/1.1 301 Moved Permanently");	header("Location: " . $siteURL . "/predictionleague/standings");	}	if(in_array($_SERVER['REQUEST_URI'],array("/games/predictionleague/?action=rules","/games/predictionleague/index.php?action=rules"))) {	header("HTTP/1.1 301 Moved Permanently");	header("Location: " . $siteURL . "/predictionleague/rules");	}	if(in_array($_SERVER['REQUEST_URI'],array("/games/predictionleague/?action=processing","/games/predictionleague/index.php?action=processing"))) {	header("HTTP/1.1 301 Moved Permanently");	header("Location: " . $siteURL . "/predictionleague/processing");	}	if(in_array($_SERVER['REQUEST_URI'],array("/games/predictionleague/?member=","/games/predictionleague/index.php?member="))) {	header("HTTP/1.1 301 Moved Permanently");	header("Location: " . $siteURL . "/predictionleague/member/" . $_GET['member'] . "");	}	if(in_array($_SERVER['REQUEST_URI'],array("/games/predictionleague/?matchday=","/games/predictionleague/index.php?matchday="))) {	header("HTTP/1.1 301 Moved Permanently");	header("Location: " . $siteURL . "/predictionleague/matchday/" . $_GET['matchday'] . "");	}

Link to comment
Share on other sites

Since the last contain $_GET[] and the first 4 dont, I'm going to guess it something to do with that. As they're dynamic url's - this may have something to do with it.What error messages are you getting?

Link to comment
Share on other sites

I took out the first four to see if the script would work but it still wasn't doing what I want it to.The main problem is, I'm not getting any error messages. So I don't really know what to do with it. :)

Link to comment
Share on other sites

It just doesn't redirect and stays on the original page. The content displays but the object of having the 301 redirects is to redirect to a new URL which has been set in the .htaccess file.

Link to comment
Share on other sites

If it's not redirecting then the if statement is not true, or you're already sending output which would stop the header and you've got error messages shut off. Assuming error messages are enabled, print the value you're checking in the if statement so you can tell what it is.

Link to comment
Share on other sites

I've managed to sort it and, as always, it's something glaringly obvious.

if(in_array($_SERVER['REQUEST_URI'],array("/games/predictionleague/?member=" . $_GET['member'] . "","/games/predictionleague/index.php?member=" . $_GET['member'] . ""))) {	header("HTTP/1.1 301 Moved Permanently");	header("Location: " . $siteURL . "/predictionleague/member/" . $_GET['member'] . "");	}if(in_array($_SERVER['REQUEST_URI'],array("/games/predictionleague/?matchday=" . $_GET['matchday'] . "","/games/predictionleague/index.php?matchday=" . $_GET['matchday'] . ""))) {	header("HTTP/1.1 301 Moved Permanently");	header("Location: " . $siteURL . "/predictionleague/matchday/" . $_GET['matchday'] . "");	}

In the actual if statement array, I hadn't got the $_GET variables. I've put them into the code and now the redirects work without a hitch.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...