subdomain error redirects to main site using htaccess

  • Answered
Any non existant subdomain gets redirected to my hosts site

would like to redirect from not existing subdomains to error page or to main domain. I have a lot of subdomains and they are created and deleted dynamically so I do not control the process and do not know what exactly subdomains are created or deleted right now.

If one user deletes his subdomain I would like to redirect visitors to main domain or just show error page with custom message, the same like it's made by

Lets say if you type any not existing subdomain it shows you error page that says that subdomain page does not exist
Hello, This is going to depend on the type of hosting that you have your website running on. It sounds like you need to setup a wildcard subdomain and DNS record if the DNS for each subdomain is getting created as your users create their accounts. If you already have wildcard subdomains and DNS setup, then you might need to place a 301 redirect via .htaccess using something like the following code: .htaccess
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ [NC]
RewriteRule ^(.*)$ [L,R=301,NC]
That code would redirect to the main website. Please let us know if you have any further questions, and if you can share any more information about the type of hosting you're using and if you're using a particular type of software as well to manage your sites. - Jacob