Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

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

Does anyone know if it's at all possible (preferably with .htaccess), to send a 404 error code and page when visiting http://www.example.com but have http://example.com working just fine?

I want to 404 the entire www website including the homepage.

share|improve this question
Why would you want to do that when you can just as easily redirect which is better for SEO and usability? – John Conde Oct 22 '12 at 22:50
it is possible with htaccess, but as mentioned, unless you want to punish the user, it's better to just redirect. – PatomaS Oct 23 '12 at 0:17
Yeah, I know it's generally not a good idea, just wanting to run this as a test that's all. – MikeHamster4 Oct 23 '12 at 12:53

Something like this should do the trick:

RewriteCond %{HTTP_HOST} ^www.domain.com [nocase]
RedirectMatch 404 ^(.*)

share|improve this answer

It makes no sense to run a HTTP server on a (v)-host if every request will result in a 404. Why not just fix your DNS setup so that the www subdomain isn't matched by any records? That way, the www variant won't even resolve.

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.