jwwceo Posted December 30, 2009 Share Posted December 30, 2009 hello, google is indexing a page in my site which is a nonsense page, with a blank GET value like this: home.php?category= where Category is NULL. It just shows my home page without doing anything. I want to try and redirect this to my home page, to give the home page the most SEO power, so I wrote the following script: if ($category == '0' || $category == NULL){ unset($category); header("HTTP/1.1 301 Moved Permanently"); header("Location: home.php"); But this just sets my home page into an infinite loop, where the page trying to be displayed is home.php?category= Any ideas why that GET value is being preserved. James Quote Link to comment https://forums.phpfreaks.com/topic/186645-301-redirect-infinite-loop/ Share on other sites More sharing options...
Mr Camouflage Posted December 30, 2009 Share Posted December 30, 2009 Because category is always null. You need to check if $_GET['category'] is set and is null then redirect. If its not set do not redirect. Also unset($category); is redundant. Quote Link to comment https://forums.phpfreaks.com/topic/186645-301-redirect-infinite-loop/#findComment-985771 Share on other sites More sharing options...
Mr Camouflage Posted December 30, 2009 Share Posted December 30, 2009 Also, you need to exit(); right after the header command, other wise the rest of your code will still be executed. Quote Link to comment https://forums.phpfreaks.com/topic/186645-301-redirect-infinite-loop/#findComment-985774 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.