开发者

What is the correct way for a webserver to respond to a request for an unrecognised host?

开发者 https://www.devze.com 2023-03-12 14:55 出处:网络
There are a few cases where, for various reasons, user agents make requests to our server for hosts that it is not configured to serve. Currently this results in them seeing the default Plesk page whi

There are a few cases where, for various reasons, user agents make requests to our server for hosts that it is not configured to serve. Currently this results in them seeing the default Plesk page which is rather hideous, so I'm going to be making a slightly prettier and faster-to-load replacement.

This got me thinking, though, and I can't find an answer to this online: What is the correct way to开发者_StackOverflow handle this situation? Should the server be responding with a 200, a 404, or some other code? Is there an HTTP status code for this situation that I've overlooked?

Lastly as a question of etiquette, what should be done in the event someone else's domain (as opposed to a domain we owned but no longer use) points at your server now (we acquired an extra IP address which was previously in use, and lives on in some incorrect DNS records).


IMHO, if user agents make a request to your server about a domain that you are not serving, then a 404 (not found) seems the most logical to me. After all the domain (and any page associated with it) does not exist on (your) server.

I would serve the 404 and log the acccesses. If you receive a high number of requests for one domain, then maybe you could try notifying the owner of the domain name (if reachable).

Edit: If the problem is the host-name header being incorrect, then I think at least IIS will return a 400 (bad request) as a response, which might be an alternative in this case.


The HTTP status codes apply to resources not domain names. The behavior is unspecified. My preference would be to redirect to a static web page with an explanation rather then send them elsewhere in the internet.

0

精彩评论

暂无评论...
验证码 换一张
取 消