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.

Incorrect. I tested it with Apache and IIS. BOTH have
$_SERVER["QUERY_STRING"] set regardless of whether a query string is present
or not.

> 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;
> }

I don't want to sound rude, but that's ridiculous. Just check to see if
$_SERVER["QUERY_STRING"] is a non-empty string. If it is, then hey-presto,
you're set. You don't need to call isset, is_array and count all in one go.

> --
> Justin Koivisto, ZCE - justin@xxxxxxxxx
> http://koivi.com


.



Relevant Pages

  • Re: Info about tuning the IIS and SPS thread settings
    ... I want to dig the role of IIS so that get clear picture so what can be done ... The amount of physical memory, in MBs, immediately available for allocation to a process or for system use on the server. ... trends begin to emerge that equate requests per second with CPU consumption ... SPS requests get routed through the IIS 6.0 as SPS also has its own thread ...
    (microsoft.public.sharepoint.portalserver)
  • Re: IIS Warm Up Period
    ... How can you prevent IIS6 server from being "dropped into the live rotation"? ... There is no built-in IIS feature for warming up. ... immediately attempts to process the requests which queue up and cause ...
    (microsoft.public.inetserver.iis)
  • Re: IIS not responding to some requests Error: 12029
    ... Error 12029 is *not* a HTTP status code. ... connect to the internet (I assume that you do *not* see anything in the IIS ... logs that matches these requests from XMLHTTP? ... The error frequency is not correlated to server activity. ...
    (microsoft.public.inetserver.iis)
  • Re: IIS6 problem
    ... Is the other IIS server IIS6 or not? ... and depending on the number of outstanding pipelined requests, ...
    (microsoft.public.inetserver.iis)
  • 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)