natasha_thomas Posted August 19, 2010 Share Posted August 19, 2010 Folks, I have around 10 sites, all were on a diffrent script earlier and indexed in Google. Now i have shifted the script and the URL structure completely changed. But in google still the Old URLs indexed. :'( I want a solution so that, any click from Old Google Indexed URLs get a 404 Error (based on the criteria below). Possible? If i can achieve this, then i will request for a "Update Cache" Request in Google. So i wll have a fresh URL structure indexed. My Old structure indexed in google looks like: http://www.abc/category1/keyword.htm www.abc/category1/keyword.htm abc/category1/keyword.htm I want help on PHP Code that will read the URL that someone clicks on Google Serp and come to my site, then the Code will Count the number of "/" OR "Forward Slashes " after the domain name: For Ex http://www.abc/category1/keyword.htm OR www.abc/category1/keyword.htm OR abc/category1/keyword.htm in this the domain name is: http://www.abc OR www.abc OR abc so the code will calculate the number of "/" after it, if the number of "/" more than 1, then a 404 Error should be returned. Can someone help me to get the PHP codes to achieve this? Best Regards, Natasha T. Quote Link to comment https://forums.phpfreaks.com/topic/211140-code-for-identify-the-old-indexed-pages-in-google-and-404-them/ Share on other sites More sharing options...
JonnoTheDev Posted August 19, 2010 Share Posted August 19, 2010 You do not use php for this. Use a .htaccess file If the URLS no longer exist simply define a 404 error document page ErrorDocument 404 /missing.html ErrorDocument 403 http://www.disney.com Quote Link to comment https://forums.phpfreaks.com/topic/211140-code-for-identify-the-old-indexed-pages-in-google-and-404-them/#findComment-1101125 Share on other sites More sharing options...
natasha_thomas Posted August 19, 2010 Author Share Posted August 19, 2010 You do not use php for this. Use a .htaccess file If the URLS no longer exist simply define a 404 error document page ErrorDocument 404 /missing.html ErrorDocument 403 http://www.disney.com Hello Neil, Thanks for the reply. R u saying that, first harvest the list of all the Old indexed URLs from Google Search engine and then define a 404 for them in .htaccess like: ErrorDocument 404 /missing.html ErrorDocument 403 http://www.abc.com/i-am-old-poor/URL1.htm ErrorDocument 403 http://www.abc.com/i-am-old-poor/URL2.htm ErrorDocument 403 http://www.abc.com/i-am-old-poor/URL3.htm ... So on.. is it what you meant? If so, then harvesting, the Old Indexed URLs is no fun and a big pain. On Another Note, i am not uisng Static HTML site, mine is a Dynamc PHP Script which Puts up site Dynamically, based on the keyword passed. One more question, am i supposed to make one /missing.htm and FTP it? Or is it just to define in .htaccess? Best Regards, Natasha T. Quote Link to comment https://forums.phpfreaks.com/topic/211140-code-for-identify-the-old-indexed-pages-in-google-and-404-them/#findComment-1101143 Share on other sites More sharing options...
JonnoTheDev Posted August 19, 2010 Share Posted August 19, 2010 No, no, no. You only need 1 404 ErrorDocument definition. The 403 rule is simply to redirect users to the url you specify if they try to access any pages/directories on your website that are forbidden! Its just force of habbit to put that in. Are you familiar with HTTP header codes? For the 404 rule you will need to create the file you specify after the rule i.e missing.html When a user trys to access a page that no longer exists they will be redirected to missing.html and a 404 header will be thrown. Here is an example of a 404 page: http://www.google.com/jhvjhvjhv.html If you want to start redirecting old urls to new urls, this is done using 301 redirects. You will have to get all the urls ready that you want to redirect to add into a .htaccess file like you stated. # redirect from old urls to new urls redirect 301 /i-am-old-poor/URL1.htm /i-am-old-poor/NEW-URL1.htm redirect 301 /i-am-old-poor/URL2.htm /i-am-old-poor/NEW-URL2.htm # redirect users to this file if they try to access a page that does not exist ErrorDocument 404 /missing.html # redirect users to this url if they try to access a resource that is forbidden ErrorDocument 403 http://www.disney.com Quote Link to comment https://forums.phpfreaks.com/topic/211140-code-for-identify-the-old-indexed-pages-in-google-and-404-them/#findComment-1101144 Share on other sites More sharing options...
JonnoTheDev Posted August 19, 2010 Share Posted August 19, 2010 Admins, this topic should be moved to mod-rewrite board. Quote Link to comment https://forums.phpfreaks.com/topic/211140-code-for-identify-the-old-indexed-pages-in-google-and-404-them/#findComment-1101145 Share on other sites More sharing options...
natasha_thomas Posted August 19, 2010 Author Share Posted August 19, 2010 Dear Neil, Thank you so much for a nice wiki, this has given me a nice solution to my problem. we write a Rule in .htaccess that will match the URL requested and if the URL requested has structure like the below: http://www.abc/anything/anything.htm www.abc/anything/anything.htm abc/anything/anything.htm It should return a 404 Error page. May i request you to help me with the Rules for the above Logic? Best Regards, Natasha Thomas Quote Link to comment https://forums.phpfreaks.com/topic/211140-code-for-identify-the-old-indexed-pages-in-google-and-404-them/#findComment-1101157 Share on other sites More sharing options...
JonnoTheDev Posted August 19, 2010 Share Posted August 19, 2010 Can you please post this request in the Mod Rewrite board. http://www.phpfreaks.com/forums/index.php/board,50.0.html Quote Link to comment https://forums.phpfreaks.com/topic/211140-code-for-identify-the-old-indexed-pages-in-google-and-404-them/#findComment-1101178 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.