Re: If isset query_string return 404



"Justin Koivisto" <justin@xxxxxxxxx> wrote in message
news:8fGdnfvFR67enVDeRVn-ow@xxxxxxxxxxxx
>d wrote:
>> "wd" <n23@xxxxxxxxxxxxxx> wrote in message
>> news:pan.2006.01.17.11.23.23.321125@xxxxxxxxxxxxxxxxx
>>> I want my server to send a 404 header if a URL with a query string is
>>> requested. So if a browser or spider requests something
>>> like
>>> www. my_site .com?p=chair
>>> they would get a 404...
>>>
>>> But if they request
>>> www. my_site .com/chair.htm
>>> everything would be normal.
>>>
>>> With some assistance this is what I have so far, but it isn't working
>>> correctly. It always displays the 404, even when there is no question
>>> mark in the URL. Also, I would like the page to stop displaying
>>> anything
>>> after the "HTML>>>" if it sends the 404 error, but I'm not sure how to
>>> do
>>> it:
>>>
>>> if (isset($_SERVER["QUERY_STRING"])) {
>>> header("HTTP/1.0 404 Not Found");
>
> [snip]
>
>> That's because $_SERVER["QUERY_STRING"] is *always* set, regardless of
>> whether there's a query string or not.
>
> Not true. With apache, QUERY_STRING will always be set; however, with
> other web server software (ie. MS IIS) it will never be set unless you
> have done so yourself.
>
> Therefore, to be more portable, you may want to do something more like
> this:

And not to mention your method only works if the query string is actually a
string of get parameters. If you pass just a string (as in his example),
the $_GET array is empty....

> if(isset($_GET) && is_array($_GET) && count($_GET)){
> header("HTTP/1.0 404 Not Found");
> echo <<< HTML
> <html>
> <head>
> <title>404 Not Found</title>
> </head>
> <body>
> <h1>Not Found</h1>
> The requested URL was not found on this server.
> </body>
> </html>
> HTML;
> exit;
> }
>
> --
> Justin Koivisto, ZCE - justin@xxxxxxxxx
> http://koivi.com


.



Relevant Pages

  • Re: Parsing a local file
    ... the browser might not enable you to do this. ... >> client machine. ... I get the file string from a query string & then parse ... >> server the application is looking for the file on the server & not on the ...
    (microsoft.public.dotnet.general)
  • Re: query parameters at the end of the JavaScript file
    ... Resource Identifiers (URI): Generic Syntax and Semantics,") for its definition of URI, and RFC 2396 makes it very clear that a query string _is_ part of a URI. ... The mans that caching GET requests without regard to their URI would be significantly faulty behaviour. ...
    (comp.lang.javascript)
  • Re: If isset query_string return 404
    ... >>> I want my server to send a 404 header if a URL with a query string is ... So if a browser or spider requests something ... >> whether there's a query string or not. ... I tested it with Apache and IIS. ...
    (comp.lang.php)
  • Re: the most cost effective way to persist page level objects in server
    ... I am not sure I understood the phrase "as long as the client stay in the same page" ... Browser send request to the server. ... ViewState that is kept on a server so it's not sent to browser. ... And other approach like form hidden fields, query string not to mention is ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: If isset query_string return 404
    ... So if a browser or spider requests something ... >>> The requested URL was not found on this server. ... >> whether there's a query string or not. ... empty, and if it is empty, then you're OK. ...
    (comp.lang.php)