Jump to content

Code for Identify the Old Indexed Pages in Google and 404 them?


natasha_thomas

Recommended Posts

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.

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.