[SOLVED] Redirect users if try to enter in a different URL

I’m in the process of learning how to make a shopping cart. I’m making good progress but some things keep getting me off track.

Here is one of those things…

If a users going to a page that does not exist on the host how do I just direct them automatically to the home page.

For example:


“sdfgswfdgsgf.php” does not exist so I want to direct them to the home page at http://www.yoursite.com

A real world example of this is at alienware.com – if you type after the “/” anything it will simply direct you to the home page.

This will help because getting an ugly error file not found message in awful.

Also another question:

When constructing my shopping cart I noticed that if someone is linked to and taken to:

the page will load fine. But if someone changes the URL to:
http://www.yoursite.com/products/index. … ct_id=5555

I will have an error (I think it was an SQL error) …

How would I fix this so that it will just default to index.php OR EVEN BETTER Right back to the Homepage like the above question.

I’m asking all of this because I want to prevent people from snooping around and trying things on my shopping cart if they wanted too.

Let me know.

Thank you for reading my questions. :)

for nonexisting pages there is a “ErrorDocoment” scefied by apache (can be done inside a .htaccess file).
this errordocument can be a php file redirecting. but i would redirect them to the search page, not the homepage (they may have used an old searchengine entry to get there).
maybe even use the nonexisting page as default searchparameter like php.net is doing: http://php.net/evaluate.php (not existing page)

the product_id=5555 error (i caan only guess) may be there because the product is not existing, buut u r running a mysql-query that is supposed (not validated) to return exactly one row. and use the result in the next query.

  1. to get rid on the error use intval e.g. mysql_query(‘SELECT … WHERE prod_id=’.intval($prodid).’ …’); that way a empty variable will be ‘0’ not ‘’ and no error is produced.
  2. u have to validate the first SELECT. maybe there was a old bookmar. so check with mysql_selected_rows() if there was a result. and if not display a nice error e.g. “this prod is no longer available, but we probably have equivalent prods [link to the prod-overview]”

that makes it much nicer for those people that ran int one of these errors, without having modified the url on their own.

Can you go more into detail about this ErrorDocoment and this .htaccess file you are talking about.

Like what do I need to do? Can it be something I can do like: an include and then upload it onto my hosting servers. Or do I have to call my hosting company up and ask them to do this on my web pages.

I’m new at this.




I want to make this topic solved.

Thanks for the help.


Sponsor our Newsletter | Privacy Policy | Terms of Service