# Redirect arbitrary sub-domains to custom 404 when wild card A record is set?

**URL:** <https://www.ruby-forum.com/t/redirect-arbitrary-sub-domains-to-custom-404-when-wild-card-a-record-is-set/214066>\
**Category:** NGINX\
**Created:** [November 20, 2011, 9:59pm UTC](https://www.ruby-forum.com/t/redirect-arbitrary-sub-domains-to-custom-404-when-wild-card-a-record-is-set/214066 "2011-11-20T21:59:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [November 20, 2011, 9:59pm UTC](https://www.ruby-forum.com/t/redirect-arbitrary-sub-domains-to-custom-404-when-wild-card-a-record-is-set/214066/1 "2011-11-20T21:59:44Z")

</div>

Is there a way to capture all requests to sub-domains which do not have  
a virtual host setup, and redirect to a custom 404 page? I will have a  
wild card A record setup \*.example.com and all our users will have a  
sub-domain [username.example.com](http://username.example.com). If someone enters a sub-domain which  
does not exist how can I redirect to a custom 404 page rather than have  
it resolve since wild card is setup?

Thanks

Posted at Nginx Forum:

> **[Redirect arbitrary sub-domains to custom 404 when wild card A record is set?](https://forum.nginx.org/read.php?2,218654,218654#msg-218654)**
>
> Is there a way to capture all requests to sub-domains which do not have a virtual host setup, and redirect to a custom 404 page? I will have a wild card A record setup \*.example.com and all our users will have a sub-domain username.example.com. If...

---

<div class="post-metadata">

**Author:** ![anagio](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/977dab/32.png) [@anagio](https://www.ruby-forum.com/u/anagio)\
**Post date:** [November 20, 2011, 11:28pm UTC](https://www.ruby-forum.com/t/redirect-arbitrary-sub-domains-to-custom-404-when-wild-card-a-record-is-set/214066/2 "2011-11-20T23:28:23Z")

</div>

On Sun, Nov 20, 2011 at 03:59:13PM -0500, anagio wrote:

Hi there,

> Is there a way to capture all requests to sub-domains which do not have  
> a virtual host setup, and redirect to a custom 404 page?

That’s called the default server.

> **[How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html)**

In that server, you can redirect or respond any way you choose.

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
