Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

404 redirect

404 redirect



5:01 pm on Jun 5, 2012 (gmt 0)


My URL is Example.com/gas.php?cid=1 and this URL is opening fine and now a URL which is Example.com/gas.php?cid=123(which actually doesnt exists) but this URL is able to open but a blank page (not even 404 error as gas.php exists) and I want to redirect this page and others where there is no information to main page i.e. Example.com/gas.php

Pls help


6:09 pm on Jun 5, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

You do this in the PHP file not in htaccess.

The first part of your PHP script should examine the requested parameters and if they are completely invalid (e.g. ?cid=1h34f3) return a 404 status code and include the 404 page code and content.

The next part of the PHP code should examine plausible parameter values (e.g. ?cid=12345) and check in the database to see if this value exists. If it does not, return a 404 status code and include the 404 page code and content.

If the parameter value is OK and is found in the database then serve the content for that id.

Do NOT redirect non-valid values. Your site will be flagged as having "soft 404 errors". You do NOT want this.

If your code begins with the !DOCTYPE then you will have to refactor your code. The PHP script should interact with the database first and the !DOCTYPE should be at least half way through the script.


7:42 pm on Jun 6, 2012 (gmt 0)


Featured Threads

Hot Threads This Week

Hot Threads This Month