jarvis Posted August 4, 2010 Share Posted August 4, 2010 Hi All, Not sure if this is the right forum or not, so here goes! Just trying to generate a sitemap using: http://www.sitemapdoc.com/Default.aspx but get the error: too many automatic redirections were attempted. I've a 301.php redirect file on my site to handle redirects and contains: if (isset($map[$_SERVER['REDIRECT_URL']])) { $new_loc = 'http://' . $_SERVER['HTTP_HOST'] . $map[$_SERVER['REDIRECT_URL']]; if (isset($_SERVER['REDIRECT_QUERY_STRING'])) { $new_loc .= '?' . $_SERVER['REDIRECT_QUERY_STRING']; } header("HTTP/1.1 301 Moved Permanently"); header("Location: $new_loc"); } else { header("HTTP/1.1 301 Moved Permanently"); header("Location: ".$_SERVER['HTTP_HOST']); } Is it an issue with my 301 causing the above error or something else? Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/209768-too-many-automatic-redirections-were-attempted/ Share on other sites More sharing options...
JonnoTheDev Posted August 4, 2010 Share Posted August 4, 2010 You are displaying a 301 header and then redirecting. Essentially you are using 2 301 redirects as the header() will use a 301 also. Use this tool to see what is happening. http://www.internetofficer.com/seo-tool/redirect-check/ Quote Link to comment https://forums.phpfreaks.com/topic/209768-too-many-automatic-redirections-were-attempted/#findComment-1095015 Share on other sites More sharing options...
jarvis Posted August 4, 2010 Author Share Posted August 4, 2010 Oh I see, so my code is at fault - nadgers! What do I need to do to my code? It's a little above me :-( Quote Link to comment https://forums.phpfreaks.com/topic/209768-too-many-automatic-redirections-were-attempted/#findComment-1095018 Share on other sites More sharing options...
JonnoTheDev Posted August 4, 2010 Share Posted August 4, 2010 Are you trying to redirect old urls to new urls? If so, you shouldn't really use code to handle this. You should use your .htaccess file to define your 404 document and any 301 redirects. It seems to me that you are redirecting to the script containing the code above which is then redirecting again. Too many redirects! Google may see this as malicious. If you put the problematic urls in the tool that i gave the link for it will tell you what is happening. Quote Link to comment https://forums.phpfreaks.com/topic/209768-too-many-automatic-redirections-were-attempted/#findComment-1095020 Share on other sites More sharing options...
jarvis Posted August 4, 2010 Author Share Posted August 4, 2010 Hi neil.johnson Yes, I'm redirecting old URLS to new ones. As there were so many, I opted for a 301.php file which listed the files old -> new. This also allowed me to display a page not found option. As the site admin configured the server to use this as the 404. Therefore, it in essessence should redirect or show the error I believe. using the tool it shows: Checked link: http://www.domain.com/tes.htm Type of redirect: 301 Moved Permanently Redirected to: http://www.domain.com/index.htm So it looks right!? Rather than using the .htaccess file, is there a simple way to alter my PHP code not to handle the double redirect? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/209768-too-many-automatic-redirections-were-attempted/#findComment-1095023 Share on other sites More sharing options...
jarvis Posted August 4, 2010 Author Share Posted August 4, 2010 Failing that, how do I alter my .htaccess file? It currently has: # -FrontPage- IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti* ErrorDocument 404 /301.php <Limit GET POST> order deny,allow deny from all allow from all </Limit> <Limit PUT DELETE> order deny,allow deny from all </Limit> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/209768-too-many-automatic-redirections-were-attempted/#findComment-1095024 Share on other sites More sharing options...
jarvis Posted August 4, 2010 Author Share Posted August 4, 2010 Should I remove the stuff in my 301.php file apart from the error, then add this to my htaccess: redirect 301 /test.htm http://www.domain.com/index.htm Repeating that for each entry I need. If so, shall I add it below: ErrorDocument 404 /301.php Or does it need to go at the end of the htaccess file, i.e. after </Limit> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/209768-too-many-automatic-redirections-were-attempted/#findComment-1095025 Share on other sites More sharing options...
JonnoTheDev Posted August 4, 2010 Share Posted August 4, 2010 This is the problem ErrorDocument 404 /301.php You are throwing a 404 to 301.php which is then throwing a 301 to a 200. This is the simplest form for your .htaccess # 404 page ErrorDocument 404 /missing.html # 301 redirects Redirect 301 http://www.foobar.com/old.html http://www.foobar.com/new.html Create a general 404 page. I have called it missing.html. On that page you could have a link back to your homepage that the user can click on. Similar to the following: http://www.bbc.co.uk/yhguyg.html Do not use the 301.php file at all Read the following http://www.isitebuild.com/301-redirect.htm Quote Link to comment https://forums.phpfreaks.com/topic/209768-too-many-automatic-redirections-were-attempted/#findComment-1095026 Share on other sites More sharing options...
jarvis Posted August 4, 2010 Author Share Posted August 4, 2010 Ah I see. Thanks, so I move the redirects into the htaccess file and then create an error page Thanks Thanks Quote Link to comment https://forums.phpfreaks.com/topic/209768-too-many-automatic-redirections-were-attempted/#findComment-1095027 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.