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.

I turned off a module in our engine, and you are correct - IIS won't set
QUERY_STRING unless prompted to. Regardless, it still doesn't merit calling
isset, is_array, and count just to check whether a string is empty 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;
> }
>
> --
> 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)
  • Server Application Unavailable
    ... Enterprise Edition running IIS 6.0 and .NET Framework 1.1. ... a "Server Application Unavailable" message in the browser. ... However, requests for other files like .asp, .htm, .gif, etc. all work ...
    (microsoft.public.inetserver.iis.security)