Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am able to do either of the following:

Host match using standard operators:

if (req.http.Host == "" || req.http.Host == "") { ... }

Host match via regex:

if (req.http.Host ~ "^(|$") { ... }

My question is, is option #2 bad performance-wise or security-wise? I understand that omitting the start and end regex characters could allow someone to put a domain like potentially, but with ^ and $ that doesn't seem possible.

Any other thoughts/ideas as to how to approach this would be appreciated.

share|improve this question

Well, I don't really think that there are any performance implications of using any of the above approaches, but I usually like to stay with the regular expression as it gives me power as well as flexibility, to match a lot of things.

Regarding the security, what you said is absolutely right and using the first option can be abused.

If I would have been working on something like this, I will surely prefer the second approach.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.