Page 1 of 1

404 missing pages - how to control dynamically?

Posted: Tue Aug 12, 2014 3:26 am
by simonmlewis
Hi.

The people who manage the sites I run sometimes change categories names, sometimes even update product IDs, and because of that, you do get URLs cached by Google (and others) that become redundant.

All these sites run from their own index.php template. So how do you identify, perhaps in index.php if the productID queried exists, and if not, take them to perhaps a 404 Error page that Google sees as a 404 or a 301?

We can manually change and do 301s in htaccess via a CSV export and just point them all to a page. But be better if it did this dynamically.

Web sites must do this kind of thing all the time, specially with sites that customers "run" (ebay, amazon, Facebook etc).

Index looks for the ID, it doesn't exist, so goes to a error.inc file. But Google doesn't see that file as a 404 or 301 direction. So how do you do that?
Can you query a database via htaccess and if the ID doesn't exist, do a 301??

Re: 404 missing pages - how to control dynamically?

Posted: Tue Aug 12, 2014 6:23 am
by phpdeveloper1
For 301, how do you want the index php script to redirect ? Based on what parameters?

Re: 404 missing pages - how to control dynamically?

Posted: Tue Aug 12, 2014 6:48 am
by simonmlewis
For 301, I want to query the database based on the the URL's $id, and if the $id is not in the system, to do a 301 to /error.

Re: 404 missing pages - how to control dynamically?

Posted: Tue Aug 12, 2014 7:00 am
by phpdeveloper1
simonmlewis wrote:For 301, I want to query the database based on the the URL's $id, and if the $id is not in the system, to do a 301 to /error.
Yes a line can be automatically added in .htaccess to do a 301 rewrite/redirect

so next time when someone accesses the page the will be redirected to not found page

But for google I'm not sure how it will work

Alternatively you can try outputting RAW header

header('HTTP/1.0 404 Not Found');

and see whether it considers the page as 404

Re: 404 missing pages - how to control dynamically?

Posted: Tue Aug 12, 2014 7:29 am
by simonmlewis
But how will the 301 work dynamically?
I know how to do a 301. But I need it to query the ID of the page it is crawling, and then do a 301.