You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Phil Endecott <sp...@chezphil.org> on 2008/01/21 00:13:51 UTC

[users@httpd] Return error code for a

Dear experts,

I was half-expecting to find that there was something like this:

<Location />
   ErrorCode 404
</Location>

that would make Apache return a particular error response for all 
matching requests.  But I can't see anything; maybe I've overlooked something?

Here's the application: I have a server with name-based virtual hosts.  
Some of my domains are email-only and I don't want Apache to serve up 
anything for them; I was recently surprised to find that it defaults to 
the first-listed virtual host when it doesn't recognise the hostname.  
To work around this, I have put an explicit default virtual host before 
the real ones:

<VirtualHost 1.2.3.4:80>
   <Location />
     ... return 404, or similar, please ....
   </Location>
</VirtualHost>

But how to return the error code?  I currently have something like this:

<VirtualHost 1.2.3.4:80>
   DocumentRoot /does/not/exist
</VirtualHost>

which feels bad, if you know what I mean.  (It's also untested, as I 
have to wait for a DNS change to propogate before I can see if it has worked.)

Any suggestions?

Thanks,  Phil.




---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Return error code for a

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
William A. Rowe, Jr. wrote:
> Phil Endecott wrote:
>> Dear experts,
>>
>> I was half-expecting to find that there was something like this:
>>
>> <Location />
>>   ErrorCode 404
>  > </Location>
> 
> Redirect 404 /
> 
> alone should probably do it, no?

Checked; that should do it.

I'd take it a step further;

     ServerAdmin nobody@example.com
     ServerName nowhere.example.com
     DocumentRoot /path/to/htdocs
     CustomLog /dev/null common env=never-log
     LogLevel crit
     KeepAlive Off
     Redirect 404 /
     ErrorDocument 404 "The requested server is not found."

giving away nothing in the responses, and wasting no time or space for
recording garbage queries.  The only 200 OK response would be in reply
to an OPTIONS *, which is harmless and reveals nothing interesting.

Some sites have a special 404 page to inform users that a modern browser
is required (e.g. help those which don't provide Host: headers) but that
issue is so ancient it's hardly worth it.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Return error code for a

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Phil Endecott wrote:
> Dear experts,
> 
> I was half-expecting to find that there was something like this:
> 
> <Location />
>   ErrorCode 404
 > </Location>

Redirect 404 /

alone should probably do it, no?


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org