Re: If isset query_string return 404



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:

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: What doesnt lend itself to OO?
    ... > system design within that context seriously). ... >>The first line exists in the server. ... > objects between client and server i.e. as far as the client code is ... the message data packet data in the server between requests, ...
    (comp.object)
  • Re: [patch 00/13] Syslets, "Threadlets", generic AIO support, v3
    ... I have an embedded server I ... I/O, audio, and child processes that handle VoIP signaling protocols ... want to throttle the concurrency of requests at the kernel level *for ...
    (Linux-Kernel)
  • Re: HttpListener BeginGetContext does not seem to handle more than 2 request simultaneously
    ... my server ran just fine and seemed to ... be aceepting/processing multiple requests simultaneously. ... System.OutOfMemoryException: Exception of type ... K> PR2 2 ...
    (microsoft.public.dotnet.framework)
  • httpd.conf apcahe2 how to make php5 module work ?
    ... # Based upon the NCSA server configuration files originally by Rob McCool. ... # configuration directives that give the server its instructions. ... Directives that control the operation of the Apache server process as a ... which allow Web requests to be sent to ...
    (freebsd-questions)
  • Re: "libexpat.so.5" not found
    ... # Based upon the NCSA server configuration files ... # This is the main Apache server configuration file. ... # configuration directives that give the server its ... # which responds to requests that aren't handled ...
    (freebsd-questions)